Nicolas
Nicolas

Reputation: 35

How to set custom font for UIAlertController

Able to set font for alert title and alert message but not for the Ok alert button.

Want to set the font for the Ok also, Thanks in advance.

let alertController = UIAlertController(title: NSLocalizedString(title, comment: ""), message: NSLocalizedString(newErrorMessage, comment: "") , preferredStyle: UIAlertController.Style.alert)
            alertController.view.tintColor = UIConfiguration.DarkGreen!
            let titleFont = LanguageManager.boldFont(size: 17.0)
            let attributedTitle = NSAttributedString(string: NSLocalizedString(title, comment: ""), attributes: [NSAttributedString.Key.font: titleFont])
            alertController.setValue(attributedTitle, forKey: "attributedTitle")
            let messageFont = LanguageManager.regularFont(size: 12.0)
            let attributedMessage = NSAttributedString(string: NSLocalizedString(newErrorMessage, comment: ""), attributes: [NSAttributedString.Key.font: messageFont])
            alertController.setValue(attributedMessage, forKey: "attributedMessage")
            
            //Unable to set the font for OK button.
            let okFont = LanguageManager.boldFont(size: 16.0)
            let attributedOk = NSAttributedString(string: NSLocalizedString("Ok", comment: ""), attributes: [NSAttributedString.Key.font: okFont])
            alertController.setValue(attributedOk, forKey: "titleTextFont")
            
            alertController.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style: .default, handler: nil))
            present(alertController, animated: true, completion: nil)

I want to set the custom font for the alert title, message and button.

Upvotes: 0

Views: 51

Answers (0)

Related Questions