ios - 将图像添加到 UIAlertController

标签 ios swift uialertcontroller unrecognized-selector

<分区>

我想向 UIAlertController 添加图像。图像不需要在按钮上,只需呈现在 Controller 中间即可。我的代码在下面,但崩溃并显示消息“无法识别的选择器已发送到实例”。

func showAlert () {

    let alert = UIAlertController(title: "Title of Alert",
        message: "none",
        preferredStyle:UIAlertControllerStyle.ActionSheet)

    // add an image
    let image = UIImage(named: "example")
    var imageView = UIImageView(image: image)
    imageView.frame = CGRectMake(0, 0, 100, 100)

    var imageAction = UIAlertAction(title: "", style:.Default, handler: nil)
    imageAction.setValue(imageView, forKey: "image")
    alert.addAction(imageAction)

    // add a continue button
    var action = UIAlertAction(title: "Continue", style:.Default, handler: {(alert:UIAlertAction!) in self.continue() })
    alert.addAction(action)

    // show the UIAlertController
    self.presentViewController(alert, animated: true, completion: nil)

}

最佳答案

不幸的是,Apple 不允许我们将图像添加到 UIAlertControllerUIAlertView。这些 API 仅限于 Apple 的人机界面指南。

如果您真的需要在类似UIAlertController 的对话框中使用图像,我建议您尝试使用类似https://github.com/wimagguc/ios-custom-alertview 的东西。 .

关于ios - 将图像添加到 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32059305/

相关文章:

ios - 世博会 React Native 应用程序。使用 expo-secure-store 方法时出错 [该方法或属性 SecureStore.setItemAsync 在 ios 上不可用]

ios - 将传入的 NSStream 转换为 View

ios - inputAccessoryView 在 alertController (actionSheet) 出现时动画化

ios - UICollectionView中的UIWebview,如何在滚动 Collection View 时停止重新加载Webview

ios - 从 WKWebView 获取所有 cookie

ios - Metal 中的纹理阵列

ios - Swift:组合两个或多个正则表达式

ios - 使用 Swift 在 iOS 11 中向 NSAttributedString 添加删除线

ios - 如何在 Swift 的 UIAlertController 中更改 UITextField 的高度?

ios - 使用破坏性样式和 UIAlertAction 删除按钮