Вы можете написать расширение для UIAlertController, как это.
extension UIAlertController {
//Set background color
func setBackgroundColor(color: UIColor) {
if let bgView = self.view.subviews.first, let groupView = bgView.subviews.first, let contentView = groupView.subviews.first {
contentView.backgroundColor = color
}
}
//Set title font and title color
func setTitleColorAndFont(font: UIFont? = UIFont.boldSystemFont(ofSize: 17.0), color: UIColor?) {
guard let title = self.title else { return }
let attributeString = NSMutableAttributedString(string: title)
if let titleFont = font {
attributeString.addAttributes([NSAttributedString.Key.font: titleFont],
range: NSRange(location: 0, length: title.utf8.count))
}
if let titleColor = color {
attributeString.addAttributes([NSAttributedString.Key.foregroundColor: titleColor],
range: NSRange(location: 0, length: title.utf8.count))
}
self.setValue(attributeString, forKey: "attributedTitle")
}
//Set message font and message color
func setMessageColorAndFont(font: UIFont? = UIFont.systemFont(ofSize: 13.0), color: UIColor?) {
guard let message = self.message else { return }
let attributeString = NSMutableAttributedString(string: message)
if let messageFont = font {
attributeString.addAttributes([NSAttributedString.Key.font: messageFont],
range: NSRange(location: 0, length: message.utf8.count))
}
if let messageColorColor = color {
attributeString.addAttributes([NSAttributedString.Key.foregroundColor: messageColorColor],
range: NSRange(location: 0, length: message.utf8.count))
}
self.setValue(attributeString, forKey: "attributedMessage")
}
}