更新时间:2023-08-30 16:35:46
很遗憾,您无法自定义警报视图的外观,也无法更改按钮文本颜色.
Unfortunately you cannot customize the appearance of alert views, it is impossible to change the buttons text color.
UIAlertView 类旨在按原样使用,而不是支持子类化.此类的视图层次结构是私有的,并且不得修改.
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
更新:
问题是关于 iOS7,但现在 UIAlertView
已弃用,对于 UIAlertController
,您可以简单地更改视图色调颜色:
The question was about iOS7, but now UIAlertView
is deprecated, for UIAlertController
you can simply change the view tint color:
let alert = UIAlertController(title: "Gimme a break",
message: "For God sake its iOS7 question!",
preferredStyle: .alert)
alert.view.tintColor = UIColor.red
检查这个问题也很有帮助:如何在 iOS9 中更改 UIAlertController 按钮文本颜色?
It is helpful also to check this question: How to change UIAlertController button text colour in iOS9?