普通弹框
//创建AlertAction
/*
参数说明:
Title:弹框的标题
message:弹框的消息内容
preferredStyle:弹框样式:UIAlertControllerStyleAlert
*/
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"我是标题啊标题啊标题啊" message:@"这个是里面的内容,喵喵喵~" preferredStyle:UIAlertControllerStyleAlert];
//添加按钮
//确认按钮
UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确认按钮");
}];
//取消按钮
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消按钮");
}];
//还可以添加文本框 通过 alert.textFields.firstObject 获得该文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请填写您的反馈";
}];
//绑定事件
[alert addAction:conform];
[alert addAction:cancel];
//显示弹框
[self presentViewController:alert animated:YES completion:nil];Action Sheet
//创建Controller
UIAlertController *alertSheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选择你的账户" preferredStyle:UIAlertControllerStyleActionSheet];
//添加按钮事件
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"账户1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了账户1");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"账户2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了账户2");
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
}];
//绑定
[alertSheet addAction:action1];
[alertSheet addAction:action2];
[alertSheet addAction:cancel];
//显示
[self presentViewController:alertSheet animated:YES completion:nil];
微信扫码查看本文
发表评论