【问题标题】:How to create UIAlertView with Image如何使用图像创建 UIAlertView
【发布时间】:2015-09-04 12:02:06
【问题描述】:

大家好,我有一个问题,是否可以在 Swift 中使用 Image 创建 UIAlertView 以及如何创建?如果有人可以帮助我,因为我在 iOS 6 中的目标 c 中没有在 iOS 7 或更高版本中找到快速练习中的网络示例。谢谢。

【问题讨论】:

    标签: ios swift uiimage uialertview


    【解决方案1】:

    在 iOS8 UIAlertView 被弃用之后,Apple 建议您使用 UIAlertController 而不是 UIAlertView。为了完成你的要求,你可以查看here

    【讨论】:

      【解决方案2】:

      这是我成功使用的解决方法。

      let myImage = UIImage(name:"myImage")
          let prevImage = UIImageView(frame: CGRect(x: 10, y: 50, width: 250, height: 172))
          prevImage.image = myImage
          let spacer = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
          let previewController = UIAlertController(title: "PREVIEW", message: spacer, preferredStyle: .Alert)
          let saveAction = UIAlertAction(title: "SAVE", style: .Default) { (UIAlertAction) in
              self.uploadPatientPhoto(myImage!)
          }
          let retakeAction = UIAlertAction(title: "RETAKE", style: .Default) { (UIAlertAction) in
              self.retakeNewPatientPhoto(self)
          }
          let cancelAction = UIAlertAction(title: "CANCEL", style: .Cancel, handler: nil)
          previewController.addAction(saveAction)
          previewController.addAction(retakeAction)
          previewController.addAction(cancelAction)
          previewController.view.addSubview(prevImage)
          presentViewController(previewController, animated: true, completion: nil)
      

      【讨论】:

      • 遗憾的是,Apple 没有提供更好的添加图像的方法,但这种方法会中断。从iOS8-iOS11。当用户在其辅助功能设置中启用较大的文本时,图像会干扰文本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 2015-09-23
      相关资源
      最近更新 更多