UIAlertController custom font, size, color

后端 未结 25 2156
遥遥无期
遥遥无期 2020-11-22 09:06

I am using new UIAlertController for showing alerts. I have this code:

// nil titles break alert interface on iOS 8.0, so we\'ll be using empty strings
UIAle         


        
25条回答
  •  鱼传尺愫
    2020-11-22 09:44

    Swift 4

    Example of custom font on the title. Same things for other components such as message or actions.

        let titleAttributed = 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")
        present(alertController, animated: true, completion: nil)
    

提交回复
热议问题