Change button title color in UIAlertView

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 08:15:31

问题


How can I change the color of the UIAlertView button title.

I want title Ok in red color.


回答1:


Actually, you can change the tint color of the view of the UIAlertController in iOS8.

UIAlertController *alertController = ....
[alertController.view setTintColor:[UIColor greenColor]];



回答2:


for Swift 3, use:

alertController.view.tintColor = UIColor.red

AFTER you present your alert controller




回答3:


The Travis Weerts answer should work if you are using a UIAlertController. For those using UIAlertView, you can use the UIView appearance settings.

You can aim the alerts component this way on iOS < 9 :

[[UIView appearanceWhenContainedIn:[UIAlertView class], nil] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];

And on iOS 9 :

[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertView class]]] setTintColor:[UIColor redColor]];
[[UIView appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]] setTintColor:[UIColor redColor]];



回答4:


The best way (And easiest) is the following:

alert = UIAlertController(title: "foo", message: "foo", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction.... foo
...foo
alert.view.backgroundColor = UIColor.orangeColor()
alert.view.tintColor = UIColor.orangeColor()
alert.view.layer.cornerRadius = 0.5 * alert.view.bounds.size.width

It gives also a plus effect of a "round faded orange circle" in the background.

Hope it helps




回答5:


Can't customize the appearance of alert views.

For more info UIAlertView Class Reference:

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.

For more info : How to change button text color of UIAlertView in iOS7?




回答6:


try this:

[[UIView appearance] setTintColor:[UIColor whiteColor]];



回答7:


You can't change alert views. If you really needed you can use custom ones.



来源:https://stackoverflow.com/questions/24157694/change-button-title-color-in-uialertview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!