ios-如何在UIAlertController中隐藏标题/消息框架?

使用ActionSheet时,如果我要显示带有空标题和空消息的UIActionSheet,则保留标题和/或消息的预期位置的框架。

如何更改此设置,以便仅显示ActionSheet,内容如下:

设定值
登出
取消?

谢谢!

UIAlertController example

vlin asked 2020-06-29T21:14:48Z
5个解决方案
115 votes

当我用此代码创建UIAlertController时,我没有标题间距。

[UIAlertController alertControllerWithTitle:nil
                                    message:nil
                             preferredStyle:UIAlertControllerStyleActionSheet];

您是否为标题和消息或空字符串输入nil?

aahrens answered 2020-06-29T21:15:06Z
6 votes

更新Swift 4:

let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)

只需将nil传递给标题和消息参数即可。

谢谢

Harjot Singh answered 2020-06-29T21:15:35Z
5 votes

如果要根据特定情况更改运行时间,只需编写:

actionController.title = nil
actionController.message = nil

beee answered 2020-06-29T21:15:59Z
1 votes

在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)
Mohsin Qureshi answered 2020-06-29T21:16:19Z
0 votes

UIAlertController * controller = [UIAlertController alertControllerWithTitle:@“”消息:@“” 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];
tushar lama answered 2020-06-29T21:16:44Z
translate from https://stackoverflow.com:/questions/29777342/how-to-hide-title-message-frame-in-a-uialertcontroller