【问题标题】:How to change UIAlertAction font?如何更改 UIAlertAction 字体?
【发布时间】:2019-02-23 08:02:06
【问题描述】:

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

【问题讨论】:

    标签: objective-c swift uialertcontroller uialertaction


    【解决方案1】:
    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)
    

    【讨论】:

    • 抱歉,这只会改变 UIAlertController 标题字体的字体。
    • 这仍然只是一个消息,而不是动作(按钮)
    • iOS系统没有提供API让我们做,所以我们最好使用第三方库。
    • 很难改,因为iOS系统没有提供API让我们改。所以我们最好使用第三方库
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多