将alertView 和 actionSheet 封装在UIAlertController 里面化整为零,使开发者更便利

当我们一味的追求高内聚,低耦合的时候,伟大的苹果反其道而行之,这也告诉了我们一个道理:

只有水平高了,内聚也就高了,耦合度自然就低了!哈哈,废话少说,直接上图:

这是整个 demo 的效果图:

下面看看 alert 相关东西的实现,直接上代码:

- (IBAction)alertAction:(id)sender {

UIAlertController * alter = [UIAlertController alertControllerWithTitle:@"通知" message:@"请填写登陆信息!"  // 初始化   alert  preferredStyle:UIAlertControllerStyleAlert];

[alter addTextFieldWithConfigurationHandler:^(UITextField *  textField) {         

/*注意:

  为 alert 添加textfield 注意 只有preferredStyle

    为UIAlertControllerStyleAlert时候才能添加textfield

  在回调的block内配置  textfield

  */ 

[textField setFrame:CGRectMake(0, 50, 44, 200)];

[textField setTextColor:[UIColor blueColor]];

[textField setPlaceholder:@"NAMEFIELD"];

[textField setClearButtonMode:(UITextFieldViewModeWhileEditing)];

[textField setBorderStyle:UITextBorderStyleRoundedRect];

}];

[alter addTextFieldWithConfigurationHandler:^(UITextField *  textField) {

[textField setFrame:CGRectMake(0, 100, 60, 200)];

[textField setTextColor:[UIColor blueColor]];

[textField setPlaceholder:@"PASSWORD"];

[textField setSecureTextEntry:YES];

[textField setClearButtonMode:(UITextFieldViewModeWhileEditing)];

[textField setBorderStyle:UITextBorderStyleRoundedRect];

}];

[alter addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action) {

/*

  在这里添加动作的实现

*/

NSLog(@"%@---%@",alter.textFields[0].text,alter.textFields[1].text);

}]];

[self presentViewController:alter animated:YES completion:nil];     // 显示 alert

}

代码撸好了,运行,点击alertAction  啪的一声,出现了如下的效果图

下面看看actionSheet 的实现

- (IBAction)actionSheet:(id)sender {

UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *  action) {

NSLog(@"---拍照获取!");

    // 再次添加实现

}]];

[alert addAction:[UIAlertAction actionWithTitle:@"从相册获取" style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action) {

NSLog(@"---从相册获取!");

      //在此添加实现

}]];

[self presentViewController:alert animated:YES completion:nil];

}

然后运行点击  ,啪的一声:

iOS 8 UIAlertController 和 UIAlertAction的更多相关文章

  1. iOS关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递页面推送

    关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递 集合嵌套集合的操作 声明 两个必须的的代理 实现部分代码 - (voi ...

  2. IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容

    IOS 修改UIAlertController的按钮标题的字体颜色,字号,内容 UIAlertController *alertVC = [UIAlertController alertControl ...

  3. iOS开发——UIAlertController

    iOS8之后,UIAlertView和UIActionSheet被干掉了,取而代之的是UIAlertController和UIAlertAction. UIAlertController有两种样式,一 ...

  4. iOS:UIAlertController和UIAlertAction的详解

    提示框控制器:UIAlertController 提示框按钮:UIAlertAction   功能:用来提示信息,并给出一些可以进行选择的按钮来处理相应的要求.   注意:在Xcode的iOS8 SD ...

  5. iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿

      iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...

  6. iOS 最新UIAlertController

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController 在实现视图控制器间的过渡动画效果和自适应设备尺 ...

  7. iOS学习——UIAlertController详解

    在开发中,弹出提示框是必不可少的.这两天项目中统一对已经被iOS API废弃的UIAlertView和UIActionSheet进行替换,我们知道,UIAlertView和UIActionSheet都 ...

  8. UIAlertController、UIAlertAction 警告框

      NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying> //创建操作 + (instan ...

  9. iOS通过UIAlertController弹出底部选择框来调用相机或者相册

    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredSt ...

随机推荐

  1. dede内容页调用图片集下所有图片方法!

    http://blog.csdn.net/forest_fire/article/details/50943765 版权声明:本文为博主原创文章,未经博主允许不得转载. {dede:productim ...

  2. dedecms织梦自定义表单发送到邮箱-用163邮箱发送邮件

    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=dedecms 邮箱&oq=d ...

  3. java开发常用jar包

    mail.jar与activation.jar 里面包含了activation.jar和mail.jar两个包.通过里面的类的调用便可以达到发送电子邮件的目的 commons-beanutils.ja ...

  4. Flex: Holy Grail

    Flex:Holy Grail <html> <head> <style type="text/css"> body,div,header,ma ...

  5. UML图学习之三 状态图

    状态图(Statechart Diagram)主要用于描述一个对象在其生存期间的动态行为,表现为一个对象所经历的状态序列,引起状态转移的事件(Event),以及因状态转移而伴随的动作(Action). ...

  6. ScrollView(RecyclerView等)为什么会自动滚动原理分析,还有阻止自动滑动的解决方案

    引言,有一天我在调试一个界面,xml布局里面包含Scroll View,里面嵌套了recyclerView的时候,界面一进去,就自动滚动到了recyclerView的那部分,百思不得其解,上网查了好多 ...

  7. js_9_dom属性

    如何设置标签属性? 找到标签 设置属性: 默认:.属性 = 属性值  //  默认属性才能用 找style中font-size : .style.fontSize     //  中间的短杆去掉,s要 ...

  8. 爬取知名社区技术文章_items_2

    item中定义获取的字段和原始数据进行处理并合法化数据 #!/usr/bin/python3 # -*- coding: utf-8 -*- import scrapy import hashlib ...

  9. Windows下为PHP安装redis扩展

    1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本. 2.下载 php_redis-2.2.7-5.5-ts-vc11-x86.zip 和 php_igbinary-2.0.5- ...

  10. redhat linux/CentOS 6/7 如何关闭防火墙?

    redhat linux/CentOS 6/7 如何关闭防火墙?关闭防火墙iptables的具体命令如下: 临时性的完全关闭防火墙,可以不重启机器(但是重启服务器后iptables防火墙服务会自动随系 ...