如何更改UIAlertAction字体?

时间:2018-09-19 07:56:30

标签: objective-c swift uialertcontroller uialertaction

有一种更改UIAlertAction字体的方法,因为我仅在UIAlertController的标题和消息中发现了如何更改字体。我还找到了如何更改颜色,但我只是找不到更改字体的方法。

1 个答案:

答案 0 :(得分:0)

let titleAttributed = NSMutableAttributedString(
        string: Constant.Strings.cancelAbsence, 
        attributes: [NSAttributedStringKey.font:UIFont(name:"FONT_NAME",size: FONT_SIZE)]
)

let messageAttributed = NSMutableAttributedString(
        string: Constant.Strings.cancelAbsence, 
        attributes: [NSAttributedStringKey.font:UIFont(name:"FONT_NAME",size: FONT_SIZE)]
)

let alertController = UIAlertController(
    title: "",
    message: "",
    preferredStyle: UIAlertControllerStyle.YOUR_STYLE
)

alertController.setValue(titleAttributed, forKey : "attributedTitle")
alertController.setValue(messageAttributed, forKey : "attributedMessage")
present(alertController, animated: true, completion: nil)