【问题标题】:How to change the alert action title color in swift 4.x or +如何在 swift 4.x 或 + 中更改警报操作标题颜色
【发布时间】:2020-02-14 01:56:42
【问题描述】:

我看到我只能使用以下语句更改警报标题颜色:

alert.setValue(NSAttributedString(string: alert.message, attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 29, weight: UIFontWeightMedium), NSForegroundColorAttributeName : UIColor.red]), forKey: "attributedTitle")

【问题讨论】:

  • 好的,你遇到了什么问题
  • 感谢 Schaheer Saleem 的回答 :)

标签: ios swift iphone layout


【解决方案1】:

使用它来更改警报操作标题颜色:

let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler:nil)
            cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor")
            alert.addAction(cancelAlert)

【讨论】:

  • 'UIAlertActionStyle' 已重命名为 'UIAlertAction.Style' 所以它应该是 let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.default, handler:nil) cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor")
  • 从未支持此代码。它可能会在以后的任何 iOS 更新中崩溃。不要尝试像这样访问私有 API。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
  • 2015-10-18
  • 1970-01-01
  • 1970-01-01
  • 2020-07-14
  • 2013-02-22
相关资源
最近更新 更多