Xcode Swift 如何将图像添加到 UIAlertController 选项?
Xcode Swift how to add image to UIAlertController options?
我想将 image/icon 添加到 UIAlertController
就像苹果音乐播放器中的对话框
我想要的 colored/sized image/icon 就像下面的图片,不像里面的那个 this question 。我相信它的 ios 11+ 功能,但我不能找到它的文档。
就像这样:
我可以在 UIAlertController
中执行此操作,还是我应该创建自己的自定义对话框 uiviewcontroller
?
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)
我想将 image/icon 添加到 UIAlertController
就像苹果音乐播放器中的对话框
我想要的 colored/sized image/icon 就像下面的图片,不像里面的那个 this question 。我相信它的 ios 11+ 功能,但我不能找到它的文档。
就像这样:
我可以在 UIAlertController
中执行此操作,还是我应该创建自己的自定义对话框 uiviewcontroller
?
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)