Xcode Swift如何将图像添加到UIAlertController选项? [重复]

问题描述 投票:2回答:1

这个问题在这里已有答案:

我想像UIAlertController一样添加图像/图标,就像苹果音乐播放器里面的对话框一样

我想要的彩色/大小的图像/图标如下图所示,而不是像this question里面的那个。我相信它的ios 11+功能,但我无法找到它的文件。

完全是这样的:

enter image description here

我可以在UIAlertController这样做,或者我应该制作我自己的自定义对话框uiviewcontroller

swift xcode uialertcontroller
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.