Подтвердить что ты не робот

Измените цвет кнопки отмены в UIAlertController с preferredStyle:.ActionSheet

Можно ли изменить цвет кнопки отмены на красный, я знаю, что мы можем с помощью деструктивного стиля

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

но я хочу кнопку отмены отдельно, например введите описание изображения здесь

4b9b3361

Ответ 1

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

Ответ 2

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

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 части

Ответ 3

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

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

})

Ответ 4

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

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