ios - 在 iOS 中更改 Alertview UIAlertController 按钮和标题颜色

标签 ios uialertcontroller tintcolor

我想根据我的应用程序主题更改我的警报 View 标题和按钮颜色,为此,我找到了以下许多解决方案:

alertController.view.tintColor = UIColor.red

但是上面的代码只改变了按钮标题的颜色,而不是警报标题。

使用 Xcode 9.1 在 iOS 11 上测试

最佳答案

使用以下代码更改警报标题:

 alertController.setValue(NSAttributedString(string: "test", attributes: [NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor : UIColor.red]), forKey: "attributedTitle")

enter image description here

关于ios - 在 iOS 中更改 Alertview UIAlertController 按钮和标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47667001/

相关文章:

ios - 向 NSAttributedString 添加左边距的最佳方法是什么?

ios - 当 UIAlertController 出现时,UIBarButtonItem 会丢失自定义外观属性

iOS UIAlertController 中断动画

ios - UITableView 单元格中的图像不支持 tintColor

ios - swift ios 核心数据是否具有预填充功能

ios - 使用 Swift 3 的核心数据指南

ios - 自定义 iOS UINavigationBar/UITabBar 和移除 Tint Colors

ios - UIButton 色调颜色影响处于选中状态的按钮的背景颜色

ios - 如何取消 iOS 中的完成处理程序

swift - 如何在 UIAlertController 中以编程方式更改特定按钮文本颜色