Swift UIAlertAction修改按键字体颜色

这需求不陌生,直接上代码。

static var propertyNames: [String] {
           var outCount: UInt32 = 0
           guard let ivars = class_copyIvarList(self, &outCount) else {
               return []
           }
           var result = [String]()
           let count = Int(outCount)
           for i in 0..

1,获取所有的属性

        func isPropertyExisted(_ propertyName: String) -> Bool {
            for name in UIAlertAction.propertyNames {
                if name == propertyName {
                    return true
                }
            }
            return false
        }

2, 是否存在某个属性


func setTextColor(_ color: UIColor) {
            let key = "_titleTextColor"
            guard isPropertyExisted(key) else {
                return
            }
            self.setValue(color, forKey: key)
        }

3,修改颜色

作为UIAlertAction 的Extension 使用即可,这个不用我赘述了吧

你可能感兴趣的:(Swift UIAlertAction修改按键字体颜色)