Change background color of a UIAlertView

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"

message: @"I'm a Chinese!"

  delegate:nil 

  cancelButtonTitle:@"Cancel" 

  otherButtonTitles:@"Okay",nil] autorelease];

[theAlert show];

/*

for(UIView *view in [theAlert subviews]){

if(view.tag ==1){

view.backgroundColor = [UIColor greenColor];

}

}

*/

UIImage *theImage = [UIImage imageNamed:@"loveChina.png"];    

theImage = [theImage stretchableImageWithLeftCapWidth:0. topCapHeight:0.];

CGSize theSize = [theAlert frame].size;

UIGraphicsBeginImageContext(theSize);    

[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    

theImage = UIGraphicsGetImageFromCurrentImageContext();    

UIGraphicsEndImageContext();

theAlert.layer.contents = (id)[theImage CGImage];

原文地址:https://www.cnblogs.com/javawebsoa/p/2458494.html