我想要一个 UIAlertView
,顶部有一个图像,图像下面有一些文本。
我知道 UIAlertView
已被弃用,但我支持 iOS 版本 7,并且 UIAlertController
在此版本中不可用。
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[imageView setImage:[UIImage imageNamed:@"icon.png"]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
NSString *about = [[NSString alloc] initWithFormat:@"%@\n\n\n\n%@\n%@\n(c) %@ Firm name", imageView, [[self bs] getAppName], [[self bs] getAppYear], [[self bs] getAppVersion]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:about delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert setValue:imageView forKey:@"accessoryView"];
[alert show];
我如何获得顶部的图像和上面的文字? 或者有人可以给我一些好的建议,如何用更好的方法解决我的问题?
编辑:我也看到了这个页面(Is it possible to show an Image in UIAlertView?),但它对我没有帮助。我仅在文本末尾看到图标。
最佳答案
几点:
UIAlertView
在 iOS 8 中已弃用。您应该改用UIAlertController
。- 对于这两种情况,您都不应该弄乱 View 层次结构。 (我过去曾在警报 View 中添加过 View ,然后 Apple 更改了一些东西但它坏了。糟糕的魔力。)
我建议使用一个看起来像警报 View 的自定义 View Controller 。以 Github 上的这个为例:
(我没用过,只是在你发的帖子里找到的。)
关于ios - 带有图像和文本的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720940/