2016-09-01 3 views
10

Можно ли изменить цвет кнопки отмены на красный, я знаю, что мы можем с помощью Убойной стильИзменения цвета кнопки отмены в UIAlertController с preferredStyle: .ActionSheet

let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Destructive) { action -> Void in 
      print("Cancel") 
     } 

, но я хочу кнопки отмены отдельно, как это enter image description here

+0

alert.view.tintColor = UIColor.redColor() –

ответ

0

Просто введите свойство стиля кнопки как разрушительное.

пусть cancelAction = UIAlertAction (название: "Отменить", стиль: .destructive, обработчик: { (предупреждение: UIAlertAction) -> Пустота в

!})

0

изменить стиль от UIAlertActionStyleDefault к UIAlertActionStyleDestructive в объективном C:

UIAlertAction* button = [UIAlertAction actionWithTitle:@"Button title here" 
             style:UIAlertActionStyleDestructive 
             handler:^(UIAlertAction * action) 
             { 
              // Handle action here.... 
             }]; 
3

Это код, как сделать предупреждение, как вы сказали:

let alert = UIAlertController(title: "Hello", message: "Hello World", preferredStyle: .actionSheet) 
alert.addAction(UIAlertAction(title: "Open in Google Maps", style: . default, handler: nil)) 
alert.addAction(UIAlertAction(title: "Open in Google", style: . default, handler: nil)) 
alert.addAction(UIAlertAction(title: "Copy Address", style: . default, handler: nil)) 

alert.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler: nil)) 

Вы должны использовать 2 вида стиля. Здесь, я использовал .destructive и .default, Он отделит действие предупреждения на 2 части

9
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) 
cancelAction.setValue(UIColor.red, forKey: "titleTextColor") 
+0

работает отлично! – user1994

+0

Насколько безопасно это решение? Что делать, если Apple решит изменить имя ключа в будущих обновлениях iOS? –

+0

Я использовал это решение в приложениях, успешно одобренных на iTunes. – Igor

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