UIAlertView和UIAlertController那点事儿
2016-07-21 13:32
435 查看
二、最基本的警告框
1、第一种方法
UIAlertView * alter = [[UIAlertView
alloc]initWithTitle:@"标题"
message:@"这个是UIAlertView的默认样式"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"好的",
nil];
[alter show];
2、第二种方法
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"标题" message:@"这个是UIAlertView的默认样式"
preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:
UIAlertActionStyleCancel handler:nil];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"登录"style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
{
NSLog(@"删除,....");
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
//记得跳转
[self presentViewController:alertController animated:YES completion:nil];
二、带有输入框的弹出框
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"文本对话框"
message:@"登录和密码的对话框示例"
preferredStyle:UIAlertControllerStyleAlert];
//UIAlertControllerStyleActionSheet
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:
UIAlertActionStyleCancel
handler:nil];
UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"登录"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
UITextField *login = alertController.textFields.firstObject;
UITextField *password = alertController.textFields.lastObject;
NSLog(@"帐号:%@",login.text);
NSLog(@"密码:%@",password.text);
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
//记得跳转
[self
presentViewController:alertController
animated:YES
completion:nil];
三、带有多个按钮删除类型的弹出框
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"保存或删除数据"
message:@"删除数据将不可恢复"
preferredStyle: UIAlertControllerStyleActionSheet];
//UIAlertControllerStyleActionSheet
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
//NSLog(@"ddd:%@",textField);
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:
UIAlertActionStyleCancel
handler:nil];
UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"删除"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"quxiao,....");
// UITextField *login = alertController.textFields.firstObject;
// UITextField *password = alertController.textFields.lastObject;
// NSLog(@"帐号:%@",login.text);
// NSLog(@"密码:%@",password.text);
}];
UIAlertAction *archiveAction = [UIAlertAction
actionWithTitle:@"保存"
style:UIAlertActionStyleDefault
handler:nil];
//
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
[alertController addAction:archiveAction];
[self
presentViewController:alertController
animated:YES
completion:nil];
1、第一种方法
UIAlertView * alter = [[UIAlertView
alloc]initWithTitle:@"标题"
message:@"这个是UIAlertView的默认样式"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"好的",
nil];
[alter show];
2、第二种方法
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"标题" message:@"这个是UIAlertView的默认样式"
preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:
UIAlertActionStyleCancel handler:nil];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"登录"style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
{
NSLog(@"删除,....");
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
//记得跳转
[self presentViewController:alertController animated:YES completion:nil];
二、带有输入框的弹出框
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"文本对话框"
message:@"登录和密码的对话框示例"
preferredStyle:UIAlertControllerStyleAlert];
//UIAlertControllerStyleActionSheet
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:
UIAlertActionStyleCancel
handler:nil];
UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"登录"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
UITextField *login = alertController.textFields.firstObject;
UITextField *password = alertController.textFields.lastObject;
NSLog(@"帐号:%@",login.text);
NSLog(@"密码:%@",password.text);
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
//记得跳转
[self
presentViewController:alertController
animated:YES
completion:nil];
三、带有多个按钮删除类型的弹出框
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"保存或删除数据"
message:@"删除数据将不可恢复"
preferredStyle: UIAlertControllerStyleActionSheet];
//UIAlertControllerStyleActionSheet
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
//NSLog(@"ddd:%@",textField);
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
textField.backgroundColor = [UIColor
orangeColor];
}];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:
UIAlertActionStyleCancel
handler:nil];
UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"删除"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"quxiao,....");
// UITextField *login = alertController.textFields.firstObject;
// UITextField *password = alertController.textFields.lastObject;
// NSLog(@"帐号:%@",login.text);
// NSLog(@"密码:%@",password.text);
}];
UIAlertAction *archiveAction = [UIAlertAction
actionWithTitle:@"保存"
style:UIAlertActionStyleDefault
handler:nil];
//
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
[alertController addAction:archiveAction];
[self
presentViewController:alertController
animated:YES
completion:nil];
相关文章推荐
- iOS UITextField 输入字数限制的实现
- hdu 1711Number Sequence
- [字符编码]Invalid byte 1 of 1-byte UTF-8 sequence终极解决方案
- 优先队列priority_queue的比较函数
- [iOS] UIBezierPath画圆弧 addArcWithCenter
- [iOS] UIBezierPath贝塞尔曲线常用方法
- (转载)uefi启动解析:由原理到实例
- iOS开发UI篇-常用控件详解(UIView)
- (译)UEFI 启动:实际工作原理
- [232] Implement Queue using Stacks
- NSView转换为NSimage 与 UIImage转换为UIimage 总结
- WebRequestHelper
- SUI的无限下拉和分页效果的实现
- NSProcessInfo获取进程信息,UIDevice获取设信息
- Wiggle Subsequence
- PHP Failed opening required (include_path='.;C:\php\pear')
- 如何在android应用里执行adb 命令深入研究java.lang.ProcessBuilder类
- Java之String、StringBuffer、StringBuilder
- Android Bluetooth(蓝牙)实例
- refind实现Win10 + Kali2.0 双引导