UIAlertController change font color

后端 未结 8 782
时光取名叫无心
时光取名叫无心 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:23

    Here's an update for Swift 4, using Cody's answer as a base:

    Setting a colour for the alert title:

    alert.setValue(NSAttributedString(string: alert.title!, attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium), NSAttributedStringKey.foregroundColor : UIColor.blue]), forKey: "attributedTitle")
    

    Setting a colour for the alert message:

    alert.setValue(NSAttributedString(string: alert.message, attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.Medium), NSAttributedStringKey.foregroundColor : UIColor.green]), forKey: "attributedMessage")
    

    As per https://developer.apple.com/documentation/foundation/nsattributedstring/key

提交回复
热议问题