2015-10-26 3 views
3

У меня есть эти строки коды:Изменить UIAlertController выбранного цвета кнопки

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]; 

Я хочу изменить кнопку отмены цвета при выборе. Как я могу это сделать? Пожалуйста, помогите.

+0

ли проверить эту ссылку у http://stackoverflow.com/questions/24157694/change-button-title-color -in-uialertview – jithin

+0

@jithin Я проверил эту ссылку, но при выборе кнопки tintColor будет изменен на цвет по умолчанию. Мой вопрос касается цвета выбранной кнопки. – Adela

ответ

6

попробовать это

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]; 

Swift

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() 
+0

Да, он работает, спасибо большое! :) – Adela

+0

приятный день, мой друг, в то же время @Ferrakkem Bhutan, Bhumica ответят также правильно, –

+0

, если мой ответ работает нормально, отдайте свой голос за ответ, он полезен для будущего –

0

Просто измените цвет оттенка на вид 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]; 
+0

Я тоже написал эту строку, но когда выбрана кнопка, цвет оттенка будет изменен на цвет по умолчанию. – Adela

+0

это ошибка в iOS 9 и Xcode 7.0.1, вы можете проверить это в Xcode 7.1 и iOS 9.1 и выше –

+0

Это не работает @ Anbu.Karthik, я пробовал эту версию, пока не задал вопрос, и у меня есть Xcode 7.1 и iOS 9.1. – Adela

-1

Попробуйте

Swift

{ 
     // 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.

+0

этот код для быстрого не для объектива-c :)) @Ferrakkem Bhuiyan – Adela

Смежные вопросы