美文网首页
Swift UIAlertAction修改按键字体颜色

Swift UIAlertAction修改按键字体颜色

作者: 周无恋 | 来源:发表于2021-06-07 09:55 被阅读0次

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

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..<count {
               let pro: Ivar = ivars[i]
               guard let ivarName = ivar_getName(pro) else {
                   continue
               }
               guard let name = String(utf8String: ivarName) else {
                   continue
               }
               result.append(name)
           }
           return result
       }

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修改按键字体颜色

      本文链接:https://www.haomeiwen.com/subject/jxaxeltx.html