Ответ 1
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
cancelAction.setValue(UIColor.red, forKey: "titleTextColor")
Можно ли изменить цвет кнопки отмены на красный, я знаю, что мы можем с помощью деструктивного стиля
let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Destructive) { action -> Void in
print("Cancel")
}
но я хочу кнопку отмены отдельно, например
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
cancelAction.setValue(UIColor.red, forKey: "titleTextColor")
Это код того, как сделать предупреждение, как вы сказали:
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 части
Просто введите свойство стиля кнопки как разрушительное.
let cancelAction = UIAlertAction (название: "Отмена", стиль:.destructive, обработчик: { (предупреждение: UIAlertAction!) → Пустота в
})
Измените стиль от UIAlertActionStyleDefault
до UIAlertActionStyleDestructive
в объекте C:
UIAlertAction* button = [UIAlertAction actionWithTitle:@"Button title here"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action)
{
// Handle action here....
}];