[英]How to change one UIAlertAction text color in a UIAlertController
[英]In UIAlertController for UIAlertAction change backgroundColor
我的目標是
如何快速自定義圖像上的 UIAlertController? 如何更改 UIAlertAction 的 backgroundColor
擴展 UILabel{ @IBInspectable public var AppearanceFont: UIFont {
get {
return self.font
}
set {
if (self.tag == 1001) {
return;
}
let isBold : Bool = (self.font.fontDescriptor.symbolicTraits.contains(.traitBold))
let colors : [CGFloat] = self.textColor.cgColor.components!
if (self.font.pointSize == 14) {
// set font for UIAlertController title
self.font = [UIFont systemFontOfSize:11];
} else if (self.font.pointSize == 13) {
// set font for UIAlertController message
self.font = [UIFont systemFontOfSize:11];
} else if (isBold) {
// set font for UIAlertAction with UIAlertActionStyleCancel
self.font = [UIFont systemFontOfSize:12];
} else if ((*colors) == 1) {
// set font for UIAlertAction with UIAlertActionStyleDestructive
self.font = [UIFont systemFontOfSize:13];
} else {
// set font for UIAlertAction with UIAlertActionStyleDefault
self.font = [UIFont systemFontOfSize:14];
// set background Color for UIAlertAction with UIAlertActionStyleDefault
let superView = self.superview?.superview
print("superView class:\(String.init(describing: superView?.classForCoder))")
if String.init(describing: superView?.classForCoder) == "Optional(_UIAlertControllerActionView)"{
print("superView.superview class:\(String.init(describing: superView?.superview?.classForCoder))")
superView?.superview?.backgroundColor = .switchTintColor
}
}
self.tag = 1001;
}
}
}
和使用添加
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).appearanceFont = UIFont.systemFont(ofSize: 14.0)
在 appDelegate 中。 它將更改所有 viewController 中警報控制器的默認 Button 的背景顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.