带有图像和文本的 UIAlertView

UIAlertView with an image and text inside

我想要一个 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?),但它对我没有帮助。我只在文本末尾看到图标。

几点:

  1. UIAlertView 在 iOS 8 中被弃用。您应该改用 UIAlertController
  2. 对于这两者,您不应该弄乱视图层次结构。 (我过去曾在警报视图中添加过视图,然后 Apple 更改了一些东西但它坏了。糟糕的魔力。)

我建议使用看起来像警报视图的自定义视图控制器。以 Github 上的这个为例:

Custom AlertView on Github

(我没用过,只是在你发的帖子里找到的。)