Here is an extension for UIAlertController that allows to add image above the title.
Ps. I use snapkit for constraints, you may want to update them with your preferred way of doing layouts.
extension UIAlertController {
func configure(with image: UIImage, title: String, handler: Action?) {
self.title = ""
addAction(UIAlertAction(
title: Localizable.Shared.cancel,
style: .default
))
addAction(UIAlertAction(
title: Localizable.Shared.yes,
style: .destructive,
handler: { [weak self] _ in
handler?()
self?.dismiss(animated: true)
}
))
let imageView = UIImageView()
imageView.image = image
let titleLabel = UILabel()
titleLabel.text = title
titleLabel.textAlignment = .center
//Configure font, color etc
view.addSubview(imageView)
view.addSubview(titleLabel)
imageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().inset(20)
make.width.height.equalTo(125)
}
titleLabel.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalTo(imageView.snp.bottom).inset(16)
}
}
}