Reputation: 1
I need to customize the background color of the UIAlertView.
I have a sample code that works perfectly on iphone 3.x, but on iphone 4 the alertview shows the default blue color.
UIAlertView *alertView =
[[[UIAlertView alloc] initWithTitle:@"Alerta"
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[alertView show];
UILabel *theTitle = [alertView valueForKey:@"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [alertView valueForKey:@"_bodyTextLabel"];
[theBody setTextColor:[UIColor whiteColor]];
UIImage *theImage = [UIImage imageNamed:@"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
CGSize theSize = [alertView frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[alertView layer] setContents:(id)theImage.CGImage];
[alertView show];
Upvotes: 0
Views: 4269
Reputation: 29524
Although it's most likely possible, it's not recommended to modify this type of stuff, as a simple update might break it. Instead, try making your own alert view as demonstrated quite nicely by Nathan S.:
How can I customize an iOS alert view?
Upvotes: 1