iphone ==> UIAlertView 改变背景?

标签 iphone background-image uialertview

我正在尝试更改 uialertview 的背景。 一切工作正常,除了我添加到 uialert View 的背景图像不会在警报 View 内缩放。所以基本上你只能看到基于当前大小的背景图像的一部分。 有什么方法可以使图像在警报 View 内缩放直到适合吗?

UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:title 
                                                    message:msg
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles: nil];
    [theAlert show];

    UIImage *theImage = [UIImage imageNamed:@"bg.jpg"];
    theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
    CGSize theSize = [theAlert frame].size;

    UIGraphicsBeginImageContext(theSize);
    [theImage drawInRect:CGRectMake(0, 0, theAlert.frame.size.width, theAlert.frame.size.height)];
    theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    theAlert.layer.contents = (id)[theImage CGImage];
    [theAlert release];

最佳答案

请看一下: http://joris.kluivers.nl/iphone-dev/?p=CustomAlert

他们解释了如何通过子类化 UIAlertView 来做到这一点。祝你好运!

关于iphone ==> UIAlertView 改变背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410782/

相关文章:

node.js - 将 HDR 照片从 iPhone 上传到网络 - GPS 数据丢失

javascript - 如何使背景图像在缩放时保持不变?

ios - 警报 View :(UIAlertView *) alertView method not working in Appdelegate

iphone - 检查 UIView 是否处于 UIScrollView 可见状态

iphone - UIGraphicsGetImageFromCurrentImageContext 的线程安全 (CG) 版本?

iphone - 使用 AFNetworking 库获取 XML 内容

html - 在同一个 div 上叠加颜色和背景图像

html - bootstrap 一行包含两个列。一个包含图像和其他背景图像

iphone - UIAlertView问题

ios - 警报 View :didDismissWithButtonIndex: message sent to deallocated instance