Как скрыть кадр заголовка/сообщения в UIAlertController?
При использовании UIAlertController
, если я хочу представить UIActionSheet
с пустым заголовком и пустым сообщением, кадр для ожидаемого размещения заголовка и/или сообщения остается.
Как мне изменить это, чтобы я представил только ActionSheet
, который гласит:
настройки
выход
Отмена
Спасибо!
![UIAlertController example]()
Ответы
Ответ 1
Когда я создаю UIAlertController с этим кодом, у меня нет промежутка между заголовками.
[UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
Вы передаете нуль для заголовка и сообщения или пустых строк?
Ответ 2
Если вы хотите изменить время выполнения в зависимости от определенного случая, просто напишите:
actionController.title = nil
actionController.message = nil
Ответ 3
UIAlertController * controller = [UIAlertController alertControllerWithTitle: @ "message: @" " preferredStyle: UIAlertControllerStyleAlert];//проверка стиля
UIAlertAction *first = [UIAlertAction actionWithTitle: @"Login with Facebook" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
//write to perform action
}];
[controller addAction: first];
UIAlertAction *second = [UIAlertAction actionWithTitle: @"Guest User" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{ // запись для выполнения действия
}];
[controller addAction:second];
UIAlertAction *third=[UIAlertAction actionWithTitle:@"Registered User" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
//write to perform action
}];
[controller addAction:third];
[self presentViewController: controller animated: YES completion: nil];
Ответ 4
В swift 2.2 вы можете использовать код ниже, и я также изменил цвет кнопки действия выхода
let actionSheet: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
self.presentViewController(actionSheet, animated: true, completion: nil)
let settingsActionButton: UIAlertAction = UIAlertAction(title: "Settings", style: .Cancel) { action -> Void in
print("Settings Tapped")
}
reportActionSheet.addAction(settingsActionButton)
let signOutActionButton: UIAlertAction = UIAlertAction(title: "Signout", style: .Default)
{ action -> Void in
//Clear All Method
print("Signout Tapped")
}
signOutActionButton.setValue(UIColor.redColor(), forKey: "titleTextColor")
actionSheet.addAction(signOutActionButton)
let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
print("Cancel Tapped")
}
reportActionSheet.addAction(cancelActionButton)