我有这个代码:
let alert = UIAlertController(title:"title", preferredStyle: UIAlertControllerStyle.alert)
let saveAction = UIAlertAction(title: "Title", style: .default, handler: nil)
var imageView = UIImageView(frame: CGRectMake(10, 10, 250, 124))
imageView.image = zdjecieGlowne
alert.view.addSubview(imageView)
alert.addAction(UIAlertAction(title: "Button 1", style: UIAlertActionStyle.default, handler: { alertAction in
print("1 pressed")
}))
alert.addAction(UIAlertAction(title: "Button 2", style: UIAlertActionStyle.cancel, handler: { alertAction in
print("2 pressed")
}))
alert.addAction(UIAlertAction(title: "Button 3", style: UIAlertActionStyle.default, handler: { alertAction in
print("3 pressed")
}))
self.present(alert, animated: true, completion: nil)
}
窗口看起来像这样: https://ibb.co/hM5zHH
图片上覆盖着我的按钮。有谁知道如何解决吗?
最佳答案
试试这个,它可能对你有帮助
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel, handler: nil)
//Add imageview to alert
let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
imgViewTitle.image = UIImage(named:"image.png")
alert.view.addSubview(imgViewTitle)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
关于ios - Swift - 带有图像的 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49791851/