Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode Swift如何将图像添加到UIAlertController选项?_Swift_Xcode_Uialertcontroller - Fatal编程技术网

Xcode Swift如何将图像添加到UIAlertController选项?

Xcode Swift如何将图像添加到UIAlertController选项?,swift,xcode,uialertcontroller,Swift,Xcode,Uialertcontroller,我想将图像/图标添加到UIAlertController中,就像apple music player中的对话框一样 我想要的是彩色/大小的图像/图标,就像下面的图像,而不是里面的图像。我相信它的ios 11+功能,但我找不到它的文档 完全像这样: 我可以在UIAlertController中执行此操作吗?或者我应该创建自己的自定义对话框uiviewcontroller?@4kman它不重复我在你的链接中看到的问题是,它有微小的图像,我想要的是同样大小的彩色图像:)答案也包括彩色图像。你能给我看

我想将图像/图标添加到
UIAlertController
中,就像apple music player中的对话框一样

我想要的是彩色/大小的图像/图标,就像下面的图像,而不是里面的图像。我相信它的ios 11+功能,但我找不到它的文档

完全像这样:


我可以在
UIAlertController
中执行此操作吗?或者我应该创建自己的自定义对话框
uiviewcontroller

@4kman它不重复我在你的链接中看到的问题是,它有微小的图像,我想要的是同样大小的彩色图像:)答案也包括彩色图像。你能给我看看你答案中选项中的彩色图像吗?@我将在你提供的链接中的选项旁边等待你彩色图像的答案:)谢谢,您可以在警报中添加多个按钮您可以查看本教程希望这有助于这里的技巧我在
UIAlertController
视图中添加图像!它的工作,但需要使它在多个选项,就像上面的图像,+1的idea@Jack . 检查我的更新answer@UmaMadhavi回答得好!知道为什么这会导致Swift 5中的布局约束问题吗?
 let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)            
 alert.modalPresentationStyle = .popover


 let image = UIImage(named: "logoCircle")
 let imageView = UIImageView()
 imageView.image = image
 imageView.frame =  CGRect(x: 25, y: 18, width: 24, height: 24)
 alert.view.addSubview(imageView) 

 let image1 = UIImage(named: "icshare")
  let imageView1 = UIImageView()
  imageView1.image = image1
  alert.view.addSubview(imageView1)
  imageView1.frame = CGRect(x: 25, y: 75, width: 24, height: 24)

 let shareExternal = UIAlertAction(title: NSLocalizedString("Share External Link", comment: ""), style: .default) { action in
        }
 let shareInApp = UIAlertAction(title: "Share within", style: .default)   {
                action in
            } 

  alert.addAction(shareInApp)
  alert.addAction(shareExternal)


    if let presenter = alert.popoverPresentationController
    {
            presenter.sourceView = button
            presenter.sourceRect = button.bounds
    }
    present(alert, animated: true, completion: nil)