UIAlertController change font color

后端 未结 8 771
时光取名叫无心
时光取名叫无心 2021-02-05 06:43

Here\'s my code that creates the UIAlertController

    // Create the alert controller
    var alertController = UIAlertController(title: \"Are you sure you want          


        
8条回答
  •  逝去的感伤
    2021-02-05 07:29

    Piyush's answer helped me the most, but here are some tweaks for Swift 3 and to change the title and message separately.

    Title:

    alert.setValue(NSAttributedString(string: alert.message, attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 29, weight: UIFontWeightMedium), NSForegroundColorAttributeName : UIColor.red]), forKey: "attributedTitle")
    

    Message:

    alert.setValue(NSAttributedString(string: alert.message, attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 29, weight: UIFontWeightMedium), NSForegroundColorAttributeName : UIColor.red]), forKey: "attributedMessage")
    

    The big font size is because I actually needed to do it for tvOS, works great on it and iOS.

提交回复
热议问题