How to edit UIAlertAction text font size and color

后端 未结 7 915
时光取名叫无心
时光取名叫无心 2020-12-06 01:33

How to edit UIAlertAction text size and color? I have taken a UIAlertController acoording to it how to edit the size. This i smy Code



        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 01:41

    I've written an extension

    extension UIAlertController{
        open override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
    
            for i in self.actions {
                let attributedText = NSAttributedString(string: i.title ?? "", attributes: [NSAttributedString.Key.font : UIFont(name: "SFProText-Semibold", size: 20.0)!])
    
                guard let label = (i.value(forKey: "__representer") as AnyObject).value(forKey: "label") as? UILabel else { return }
                label.attributedText = attributedText
            }
    
        }
    }
    

提交回复
热议问题