UIAlertController小示例
2015-12-17 18:49
417 查看
ios9新加的UIAlertController,感觉不错挺好用,当做个笔记
- (void)viewDidLoad {
[super
viewDidLoad];
UIButton * button1 = [[UIButton
alloc]initWithFrame:CGRectMake(100,
100, 100,
50)];
[button1 setTitle:@"ActionSheet"
forState:UIControlStateNormal];
button1.backgroundColor = [UIColor
blackColor];
[button1 addTarget:self
action:@selector(showActionSheet)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button1];
UIButton * button2 = [[UIButton
alloc]initWithFrame:CGRectMake(100,
170, 100,
50)];
[button2 setTitle:@"AlertView"
forState:UIControlStateNormal];
button2.backgroundColor = [UIColor
blackColor];
[button2 addTarget:self
action:@selector(showAlertView)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button2];
}
#pragma mark action sheet
- (void)showActionSheet
{
UIAlertController * alertC = [UIAlertController
alertControllerWithTitle:@"提示"
message:@"今天星期四"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * defaultBtn = [UIAlertAction
actionWithTitle:@"普通"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"点击了普通按钮");
}];
UIAlertAction * cancelBtn = [UIAlertAction
actionWithTitle:@"取消"
style:UIAle
4000
rtActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction * destBtn = [UIAlertAction
actionWithTitle:@"销毁"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"点击了销毁按钮");
}];
//添加到actionsheet
[alertC addAction:defaultBtn];
[alertC addAction:cancelBtn];
[alertC addAction:destBtn];
//显示到屏幕
[self
presentViewController:alertC animated:YES
completion:nil];
}
#pragma mark alert view
- (void)showAlertView
{
UIAlertController * alertC = [UIAlertController
alertControllerWithTitle:@"提示"
message:@"后天星期六是个好日子"
preferredStyle:UIAlertControllerStyleAlert];
//添加按钮
UIAlertAction * cancelBtn = [UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction * destBtn = [UIAlertAction
actionWithTitle:@"重置"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"点击了重置按钮");
//获取输入框的内容
UITextField * tf = alertC.textFields[0];
NSLog(@"%@",tf.text);
}];
//将按钮添加到弹框上
[alertC addAction:cancelBtn];
[alertC addAction:destBtn];
//添加输入框
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入用户名";
}];
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入密码";
}];
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入银行卡密码";
}];
//显示到屏幕上
[self
presentViewController:alertC animated:YES
completion:nil];
}
- (void)viewDidLoad {
[super
viewDidLoad];
UIButton * button1 = [[UIButton
alloc]initWithFrame:CGRectMake(100,
100, 100,
50)];
[button1 setTitle:@"ActionSheet"
forState:UIControlStateNormal];
button1.backgroundColor = [UIColor
blackColor];
[button1 addTarget:self
action:@selector(showActionSheet)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button1];
UIButton * button2 = [[UIButton
alloc]initWithFrame:CGRectMake(100,
170, 100,
50)];
[button2 setTitle:@"AlertView"
forState:UIControlStateNormal];
button2.backgroundColor = [UIColor
blackColor];
[button2 addTarget:self
action:@selector(showAlertView)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button2];
}
#pragma mark action sheet
- (void)showActionSheet
{
UIAlertController * alertC = [UIAlertController
alertControllerWithTitle:@"提示"
message:@"今天星期四"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * defaultBtn = [UIAlertAction
actionWithTitle:@"普通"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"点击了普通按钮");
}];
UIAlertAction * cancelBtn = [UIAlertAction
actionWithTitle:@"取消"
style:UIAle
4000
rtActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction * destBtn = [UIAlertAction
actionWithTitle:@"销毁"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"点击了销毁按钮");
}];
//添加到actionsheet
[alertC addAction:defaultBtn];
[alertC addAction:cancelBtn];
[alertC addAction:destBtn];
//显示到屏幕
[self
presentViewController:alertC animated:YES
completion:nil];
}
#pragma mark alert view
- (void)showAlertView
{
UIAlertController * alertC = [UIAlertController
alertControllerWithTitle:@"提示"
message:@"后天星期六是个好日子"
preferredStyle:UIAlertControllerStyleAlert];
//添加按钮
UIAlertAction * cancelBtn = [UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction * destBtn = [UIAlertAction
actionWithTitle:@"重置"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"点击了重置按钮");
//获取输入框的内容
UITextField * tf = alertC.textFields[0];
NSLog(@"%@",tf.text);
}];
//将按钮添加到弹框上
[alertC addAction:cancelBtn];
[alertC addAction:destBtn];
//添加输入框
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入用户名";
}];
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入密码";
}];
[alertC addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder =
@"请输入银行卡密码";
}];
//显示到屏幕上
[self
presentViewController:alertC animated:YES
completion:nil];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 个人信息安全报告发布:有 APP 每分钟调用位置权限 1468 次
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- 下载量超过一亿的流行应用被发现含有恶意模块
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 苹果与Siri的七年之痒:“宫斗”戏码不断上演
- 新注册
- 四大漏洞入侵博客
- 在Ubuntu系统上安装Ghost博客平台的教程
- Android APP与媒体存储服务的交互
- java实现收藏名言语句台词的app
- 修改Android App样式风格的方法
- Android App数据格式Json解析方法和常见问题
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略