iOS - 提示信息 - UIAlertView、UIActionSheet、UIAlertController的实际应用
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"done", nil];
//设置alertView的样式
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
//使alertView展示出来
[alertView show];
//延迟5秒执行dismissAlertView
[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:5];
// alertview消失的方法
-(void)dismissAlertView:(UIAlertView*)alert{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
//点击alertView button 触发的方法。
//buttonIndex按钮的索引值 cancel的index为0
//(代理方法)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
//获取alertview上的输入文本
UITextField * textField1 = [alertView textFieldAtIndex:0];
NSLog(@"%@",textField1.text);
2、UIActionSheet(屏幕底端出现)
UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"题目" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"可以", nil];
//destructiveButtonTitle 红色字体
//使sheet显示出来
[sheet showInView:self.view];
//延迟5秒执行dismissAlertView
[self performSelector:@selector(dismissActionSheet:) withObject:sheet afterDelay:5];
// sheet 消失的方法
[sheet dismissWithClickedButtonIndex:0 animated:YES];
//代理方法(index顺序从上到下)
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
NSLog(@"确定");
break;
case 1:
NSLog(@"可以");
break;
case 2:
NSLog(@"取消");
break;
default:
break;
}
}
3、UIAlertController
//创建UIAlertController
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"题目" message:@"消息" preferredStyle:UIAlertControllerStyleAlert];
//创建按钮
UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"no");
}];
UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
NSLog(@"ok");
UITextField * field = alertController.textFields[0];
NSLog(@"%@",field.text);
}];
//添加文本
[alertController addTextFieldWithConfigurationHandler:^(UITextField * textField) {
textField.secureTextEntry = YES;
}];
[alertController addAction:action1];
[alertController addAction:action2];
//展示alertController
[self presentViewController:alertController animated:YES completion:nil];
iOS - 提示信息 - UIAlertView、UIActionSheet、UIAlertController的实际应用的更多相关文章
- iOS开发之UIAlertView与UIAlertController的详尽用法说明
本文将从四个方面对IOS开发中UIAlertView与UIAlertController的用法进行讲解: 一.UIAlertView与UIAlertController是什么东东? 二.我们为什么要用 ...
- ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结
首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...
- 在iOS 8中使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
- 【iOS】swift-ObjectC 在iOS 8中使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
- UIAlertView和UIAlertController
UIAlertView 随着苹果上次iOS 5的发布,对话框视图样式出现在了我们面前,直到现在它都没有发生过很大的变化.下面的代码片段展示了如何初始化和显示一个带有“取消”和“好的”按钮的对话框视图. ...
- iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色
废话不多说,直接上代码,效果是最好的说服力 1.改变UIAlertView字体颜色 [UIView appearance].tintColor = [UIColor greenColor]; 个人还是 ...
- iOS 9.0中UIAlertController的用法。
1.我为什么要写这篇博客记录它? 答:因为 UIAlertView和UIActionSheet 被划线了 苹果不推荐我们使用这两个类了,也不再进行维护和更新,为了以后方便使用我来记录一下.如图所示 正 ...
- iOS 9.0中UIAlertController的用法
UIAlertView和UIActionSheet 被划线了. 苹果不推荐我们使用这两个类了.也不再进行维护和更新 正如苹果所说它现在让我们用UIAlertConntroller 并设置样式为UIAl ...
- iOS学习之UIActionSheet的使用
UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件. 为了快速完成这例子,我们打开Xcode 4.3.2, 先建立一个single view applicatio ...
随机推荐
- Oracle数据库定时任务配置和日志执行情况查询
基础配置: /***************************************************************** * * 移动抵扣券快到期推送提醒 * 首次执行 : 2 ...
- PostQuitMessage, PostThreadMessage( WM_QUIT )
http://blogs.msdn.com/b/oldnewthing/archive/2005/11/04/489028.aspx Why is there a special PostQuitMe ...
- 解决IE6不支持position:fixed属性
最近在优化网站浮动广告时候遇见了IE6不支持position:fixed属性.上网收集了一下解决方案 比较好的方案就是利用css表达式进行解决 补充:CSS Expression (CSS 表达式), ...
- radvd.conf RADVD配置文件内容部分解析
interface eth0{ AdvSendAdvert on; #启用路由器公告(RA)功能 MinRtrAdvInterval ; #每隔30-100秒间隔发送公告消息 MaxRtrAdvInt ...
- hdu 5258 数长方形 离散化
数长方形 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5258 Des ...
- HDU 4278 Faulty Odometer 8进制转10进制
Faulty Odometer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- C++ 内存泄露处理方法 (转)
1.可以显示内存泄露情况,但无法找到具体的文件位置写法 包含头文件#include <crtdbg.h> 然后在需要检测内存泄露的位置加上语句 _CrtDumpMemoryLeaks(); ...
- FindMe
https://github.com/hongdong/FindMe_Android https://github.com/hongdong/FindMe_Server https://github. ...
- android IPC及原理简介
什么是Android操作系统,所谓的Android:是基于Linux内核的软件平台和操作系统,早期由Google开发,后由开放手机联盟Open Handset Alliance)开发. Linux ...
- PHP函数spl_autoload_register()用法和__autoload()介绍(转)
详细出处参考:http://www.jb51.net/article/29624.htm 又是框架冲突导致__autoload()失效,用spl_autoload_register()重构一下,问题解 ...