给AlertView添加图片背景

UIAlertView *theAlert = [[[UIAlertViewalloc]

initWithTitle:@"Attention"

message:@"I'm a Chinese!"delegate:nilcancelButtonTitle:@"Cancel"

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

[theAlert show];

UIImage *theImage =

[UIImageimageNamed:@"loveChina.png"];

theImage = [theImage

stretchableImageWithLeftCapWidth:0topCapHeight:0];

CGSize theSize = [theAlert frame].size;

UIGraphicsBeginImageContext(theSize);

[theImage drawInRect:CGRectMake(5, 5,

theSize.width-10, theSize.height-20)];

theImage =

UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

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

posted @ 2016-11-16 23:54  华少不思议  阅读(146)  评论(0编辑  收藏  举报