苹果手机==> UIAlertView改变背景?
我正在尝试更改 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请看一下:
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!