更改AlertView背景

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

                                                        message: @"I'm a Chinese!"

                                                       delegate:nil 

                                              cancelButtonTitle:@"Cancel" 

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

    [theAlert show];

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

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

    CGSize theSize = [theAlert frame].size;

    

    UIGraphicsBeginImageContext(theSize);    

    [theImage drawInRect:CGRectMake(55, theSize.width-10, theSize.height-20)]; //这个地方的大小要自己调整,以适应alertview的背景颜色的大小。

    theImage = UIGraphicsGetImageFromCurrentImageContext();    

    UIGraphicsEndImageContext();

    theAlert.layer.contents = (id)[theImage CGImage];
posted @ 2013-04-24 21:54  夏了′夏天  Views(114)  Comments(0Edit  收藏  举报