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..<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 使用即可,这个不用我赘述了吧

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容