【问题标题】:Change UIAlertController selected button color更改 UIAlertController 选择的按钮颜色
【发布时间】:2015-10-26 11:53:26
【问题描述】:

我有这行代码:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
    NSLog(@"cancel registration");
}];
[alertController addAction:cancelAction];
alertController.view.tintColor = [UIColor redColor];

我想在选中时更改取消按钮的颜色。我怎样才能做到这一点? 请帮忙。

【问题讨论】:

  • @ jithin i检查了此链接,但选择按钮时,TintColor会更改为默认颜色。我的问题是关于所选按钮的颜色。

标签: ios objective-c swift uialertcontroller


【解决方案1】:

试试这个

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"cancel registration");
}];
[alertController addAction:cancelAction];

尝试设置色调颜色之后你展示你的警报控制器:

[self presentViewController: alertController animated:YES completion:nil];
 alertController.view.tintColor = [UIColor redColor];

斯威夫特

var alertController: UIAlertController = UIAlertController.alertControllerWithTitle(title, message: nil, preferredStyle: .ActionSheet)
var cancelAction: UIAlertAction = UIAlertAction.actionWithTitle(cancelTitle, style: .Cancel, handler: {(action: UIAlertAction) -> Void in
    NSLog("cancel registration")
})
alertController.addAction(cancelAction)

尝试设置色调颜色之后你展示你的警报控制器:

self.presentViewController(alertController, animated: true, completion: { _ in })
alertController.view.tintColor = UIColor.redColor()

【讨论】:

  • 祝我的朋友度过愉快的一天,同时@Ferrakkem Bhutan,Bhumica 的回答也正确,
  • 如果我的回答很好,请给答案投赞成票,这对未来很有用
  • 当我说“谢谢”时,我投了你赞成票 :) @Anbu.Karthik
【解决方案2】:

只需更改UIAlertController 视图上的色调颜色。

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
    NSLog(@"cancel registration");
     alertController.view.tintColor = [UIColor redColor];
}];
[alertController addAction:cancelAction];

【讨论】:

  • 我也写了这一行,但是当按钮被选中时,色调颜色变成了默认颜色。
  • 这是 iOS 9 和 Xcode 7.0.1 的 bug,你可以在 Xcode 7.1 和 iOS 9.1 及更高版本中查看
  • 它不起作用@Anbu.Karthik,我尝试了这个版本,直到提出问题并且我有 Xcode 7.1 和 iOS 9.1。
【解决方案3】:

试试这个

斯威夫特

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        alertController.view.tintColor = UIColor.redColor()
    }

Objective-C

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        alertController.view.tintColor = [UIColor redColor];
    }

更多详情Click Here.

【讨论】:

  • 此代码用于 swift 而不是用于 Objective-c :)) @Ferrakkem Bhuiyan
猜你喜欢
  • 1970-01-01
  • 2012-01-16
  • 1970-01-01
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多