ios开发之改变UIAlertView背景图片

UIAlertView *theAlert = [[[UIAlertView alloc] 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: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];

你可能感兴趣的:(ios)