我已经看过UIAlertControllers的几个屏幕截图,在行的左边有一个图像,但我没有在文档中看到它 . 一个可视化示例是
这是我现在为我的控制器提供的代码:
UIAlertController * view = [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Select you Choice"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
[view addAction:ok];
[self presentViewController:view animated:YES completion:nil];
7 回答
这就是它的完成方式:
image属性没有公开,所以在将来的版本中无法保证这一点,但是现在工作正常
尝试这样的事情:
经过测试,适用于iOS 7.0
您可以通过继承
UIAlertController
并将\n
添加到 Headers 字符串以在UIImageView
中添加空格来在 Headers 标签上方添加图像 . 您必须根据字体大小计算布局 . 对于UIAlertAction
中使用KVC
的图像,如此self.setValue(image, forKey: "image")
. 我建议检查responds(to:)
的扩展名 . Here is sample implementation.For swift
Note: IMP Line withRenderingMode(.alwaysOriginal)
Swift版本:
swift 3扩展,属性和便利init .
感谢Shahar Stern的灵感