I have this code:
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)
}
The window looks like this: https://ibb.co/hM5zHH
The picture covers me with the buttons. Does anyone know how to fix it?
Try this, it may helps you
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)
In my opinion UIAlertController shouldn't be used to show some option with image, instead you should implement custom UIView and handle presentation logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With