Changing the background color of a UIAlertView?

前端 未结 12 1104
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 03:12

I want to change the background color of my UIAlertView, but this doesn\'t appear to have a color attribute.

12条回答
  •  抹茶落季
    2020-11-28 04:05

    Background of AlertView is an image And you can change this image

    UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"
       message: @"YOUR MESSAGE HERE", nil)
       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
    
       [theAlert show];
    
       UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"];
       [theTitle setTextColor:[UIColor redColor]];
    
       UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"];
       [theBody setTextColor:[UIColor blueColor]];
    
       UIImage *theImage = [UIImage imageNamed:@"Background.png"];    
       theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
       CGSize theSize = [theAlert frame].size;
    
       UIGraphicsBeginImageContext(theSize);    
       [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
       theImage = UIGraphicsGetImageFromCurrentImageContext();    
       UIGraphicsEndImageContext();
    
       [[theAlert layer] setContents:[theImage CGImage]];
    

提交回复
热议问题