Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改UIAlertController所选按钮的颜色_Ios_Objective C_Swift_Uialertcontroller - Fatal编程技术网

Ios 更改UIAlertController所选按钮的颜色

Ios 更改UIAlertController所选按钮的颜色,ios,objective-c,swift,uialertcontroller,Ios,Objective C,Swift,Uialertcontroller,我有以下几行代码: UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActi

我有以下几行代码:

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];
选择时,我想更改取消按钮的颜色。我该怎么做?
请提供帮助。

只需更改
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];
试试这个

Swift

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        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)
目标-C

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        alertController.view.tintColor = [UIColor redColor];
    }
有关更多详细信息,请尝试此

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];
在呈现警报控制器后,尝试设置色调颜色:

Swift

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        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)
在呈现警报控制器后,尝试设置色调颜色:


你是否检查了此链接@jithin我检查了此链接,但选中按钮后,tintColor将更改为默认颜色。我的问题是关于所选按钮的颜色。我也写了这行,但当按钮被选中时,色调颜色变成默认颜色。这是iOS 9和Xcode 7.0.1中的错误,您可以在Xcode 7.1和iOS 9.1及以上版本中检查它不起作用@Anbu.Karthik,我尝试了这个版本,直到问问题,我有Xcode 7.1和iOS 9.1。这个代码是swift而不是objective-c:)@Ferrakkem Bhuiyanhave Good day我的朋友,同时@Ferrakkem Dundan,Bhumica的答案也正确,如果我的答案运行良好,请投反对票,这对未来很有用当我说“谢谢”时,我给了你投票权:)@Anbu.Karthik