Fork me on GitHub

改变Alert的背景图片

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"
                                                        message: @"XXXXX!"
                                                       delegate:nil 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:@"Okay",nil] autorelease]; 
    [theAlert show];
    UIImage *theImage = [UIImage imageNamed:@"XXX.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];

posted on 2012-03-03 23:35  pengyingh  阅读(691)  评论(0编辑  收藏  举报

导航