【问题标题】:Change button title color in UIAlertView更改 UIAlertView 中的按钮标题颜色
【发布时间】:2014-08-01 04:50:47
【问题描述】:

如何更改UIAlertView 按钮标题的颜色。

我想要红色的标题Ok

【问题讨论】:

标签: ios iphone objective-c uialertview


【解决方案1】:

其实你可以在iOS8中改变UIAlertController的view的tint color。

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

【讨论】:

  • 如果您继承 UIAlertController 并在 viewDidLoad 中设置 tintColor,则此方法有效。
【解决方案2】:

对于 Swift 3,使用:

alertController.view.tintColor = UIColor.red

之后你展示了你的警报控制器

【讨论】:

  • 在出现警报控制器之前它也对我有用
  • “之后”不是必需的。 :)
【解决方案3】:

如果您使用的是UIAlertController,Travis Weerts 的答案应该可以工作。对于使用UIAlertView 的用户,您可以使用UIView 外观设置。

您可以通过这种方式在 iOS 上瞄准警报组件:

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

在 iOS 9 上

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

【讨论】:

    【解决方案4】:

    最好的方法(也是最简单的)如下:

    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
    

    它还在背景中提供了“圆形褪色橙色圆圈”的加号效果。

    希望对你有帮助

    【讨论】:

      【解决方案5】:

      无法自定义警报视图的外观。

      欲了解更多信息UIAlertView Class Reference:

      UIAlertView 类旨在按原样使用,而不是 支持子类化。此类的视图层次结构是私有的,并且 不得修改。

      更多信息: How to change button text color of UIAlertView in iOS7?

      【讨论】:

      • @NitinGohel 虽然它们看起来更简单,但我认为它不能以任何其他方式表达,因为这基本上来自 Apple 文档。
      • 但确实是从我粘贴的链接中复制的。
      • @NitinGohel 我想,但我真的不认为它可以用其他任何方式表达,一句话确实涵盖了整个事情并且绝对是一个正确的答案,所以我不认为它应该只是评论。我想如果用户从您提供的链接中引用它会更好。
      【解决方案6】:

      试试这个:

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

      【讨论】:

        【解决方案7】:

        您无法更改警报视图。如果你真的需要,你可以使用custom ones

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-10-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多