苹果手机==> UIAlertView改变背景?

发布于 2024-09-13 14:45:04 字数 992 浏览 3 评论 0原文

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

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];

I am trying to change the background of the uialertview.
Everything works fine except the background image i am adding to the uialert view won't scale inside the alertview. So basically you see only part of my background image based on the current size.
Is there any way to make it so that the image scales inside the alerview until it fits?

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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟燃烟灭 2024-09-20 14:45:04

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

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

please take a look at:
http://joris.kluivers.nl/iphone-dev/?p=CustomAlert

They explain how to do it by subclassing UIAlertView. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文