ios UIAlertAction 改变颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27484657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 04:01:46  来源:igfitidea点击:

UIAlertAction change color

iosuialertcontroller

提问by borchero

How can one change the color of a UIAlertActionbutton, that has been added to an UIAlertController?

如何更改UIAlertAction已添加到 的按钮的颜色UIAlertController

采纳答案by Salman Zaidi

Refer following post:

参考以下帖子:

Change Text Color of Items in UIActionSheet - iOS 8

更改 UIActionSheet 中项目的文本颜色 - iOS 8

Although it's related to changing color of UIActionSheetitems but one user has answered according to change color of UIAlertActionitems.

虽然它与更改UIActionSheet项目的颜色有关,但一位用户已根据UIAlertAction项目的更改颜色进行了回答。

回答by Sylver

No need to do some complicated things, you only need to change the tintColor property of the UIAlertController main view like this :

不需要做一些复杂的事情,你只需要像这样更改 UIAlertController 主视图的 tintColor 属性:

let alert = UIAlertController(title: "Title", message: "Some message", preferredStyle: .Alert)
alert.view.tintColor = UIColor.redColor()
let action = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(action)

This way your buttons tint will be red (or whatever color you want)

这样你的按钮就会变成红色(或者你想要的任何颜色)