Changing the background color of a UIAlertView?

前端 未结 12 1102
爱一瞬间的悲伤
爱一瞬间的悲伤 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 03:55

    I don't believe that there is an exposed method or property for doing this. Setting the backgroundColor of the UIAlertView (as a UIView) merely puts a colored rectangular backdrop behind the alert view.

    I'd say that it would probably go against the common interface of the iPhone to alter this color, so I don't think it's recommended behavior (in the same way that changing the background color of an alert view in Mac OS X is not recommended).

    0 讨论(0)
  • 2020-11-28 03:56

    Add QuartzCore framework to the application and include #import "QuartzCore/CALayer.h" in the source file.

    0 讨论(0)
  • 2020-11-28 03:56

    This looks like the most robust solution to me

    http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uialertview-custom-graphics/

    0 讨论(0)
  • 2020-11-28 03:58

    I recently found the GRAlertView, which allow you to tailor UIAlertView in an easy way that at least I like. You find it here: https://github.com/goncz9/GRAlertView

    0 讨论(0)
  • 2020-11-28 03:59

    I've also find an almost identical workaround and, in my case, it works better. Using oxigen way out i've discovered a poor result on the screen and the context get blurred. Rather than subclassing UIAlertView I implement:

    - (void)willPresentAlertView:(UIAlertView *)alertView;
    

    so...just copy & paste

    - (void)willPresentAlertView:(UIAlertView *)alertView 
    {
        blah blah blah...
        [[alertView layer] setContents:(id)theImage.CGImage];  // to avoid the warning
    }
    
    0 讨论(0)
  • 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]];
    
    0 讨论(0)
提交回复
热议问题