Wednesday, December 27, 2023
HomeiOS Developmentios - Find out how to set customized font for UIAlertController

ios – Find out how to set customized font for UIAlertController


Capable of set font for alert title and alert message however not for the Okay alert button.

Wish to set the font for the Okay additionally, Thanks upfront.

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

I wish to set the customized font for the alert title, message and button.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments