今天大家讲讲总能在APP中看到的提示框,也是一个常见的控件。
我今天用的storyboard铺的 方便大家能看出是哪种类型的对话框(提示框)
一.弹出对话框
#pragma mark - cancle按钮一直在最下边 且只能有一个
/*** 弹出对话框 */
- (void)createAlterController
{
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"保存" preferredStyle:UIAlertControllerStyleAlert];
//确定按钮的风格是默认的
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"确定");
//添加你自己让他发生的事件 都是一样的!!!!!
}];
//取消按钮的风格是取消, 并且一直在最下边,且只能有一个
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *delete = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:nil];
[alter addAction:sure];
[alter addAction:cancle];
[alter addAction:delete];
[self presentViewController:alter animated:YES completion:^{
}];
}
二.文本对话框
- (void)createUIAlertControllerWithTextField
{
UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"文本对话框" message:@"保存" preferredStyle:UIAlertControllerStyleAlert];
[alert2 addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入用户名" ;
}];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// UITextField *longinTextField = alert2.textFields.firstObject;
// UITextField *pad = alert2.textFields.lastObject;
}];
[alert2 addAction:sure];
[self presentViewController:alert2 animated:YES completion:^{
}];
}
三.上拉菜单
- (void)create
{
UIAlertController *sheet = [UIAlertController alertControllerWithTitle:@"上拉对话框" message:@"保存" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *delete = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:nil];
[sheet addAction:sure];
[sheet addAction:cancle];
[sheet addAction:delete];
[self presentViewController:sheet animated:YES completion:^{
}];
}
最后注意这三种的UIAlertViewController的风格前两种是UIAlertControllerStyleAlert
后一种是UIAlertControllerStyleActionSheet 希望对大家有用吧!!!!!