ios - 带有图像和文本的 UIAlertView

标签 ios iphone uiimageview uialertview uialertcontroller

我想要一个 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. 对于这两种情况,您都不应该弄乱 View 层次结构。 (我过去曾在警报 View 中添加过 View ,然后 Apple 更改了一些东西但它坏了。糟糕的魔力。)

我建议使用一个看起来像警报 View 的自定义 View Controller 。以 Github 上的这个为例:

Custom AlertView on Github

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

关于ios - 带有图像和文本的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720940/

相关文章:

ios - 如何使Table View的FIRST分隔符透明(不透明)?

ios - 我什么时候可以设置 NMAMapMarker 的大小?

iphone - NSCollectionView for Cocoa-Touch (iPhone/iPad)

iOS - 表格 View 单元格无法正确呈现

ios - 渐变不覆盖全帧 SWIFT

ios - MvvmCross:如何使用 ICommand 再次调用当前 View 模型?

iphone - 垂直颜色渐变

iphone - UIImagePickerControllerEditedImage 问题

ios - 当图像因内容模式而缩小时,使 ImageView 调整其高度以匹配其图像的高度

html - Safari for iOS 上垂直 flexbox 中的最后一个元素在横向模式下被裁剪