提示效果

关于iOS开发提示效果是一个很常见的技术,比如我们平时点击一个按钮,实现回馈,或者发送网络请求的时候!

技术点:

一:View

UIAlertView

UIActionSheet

二:控制器

UIAlertController

三:第三方库

SVProgressHUD

MBProgressHUD

下面是主界面:

首先我们来看看系统自带的一些提示框(View)

一::UIAlertView

1:创建UIalertView(这里只说纯代码创建的方式)

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示框" message:@"请选择" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
     [alert show];

当我们点击对应地方就会弹出一个提示框

如果我们需要实现监听点击那一个按钮就需要遵守协议,并且实现相应的代理方法:

遵守的协议:  UIAlertViewDelegate

实现代理方法,这里我们只实现了一个点击相应按钮的代理监听方法,平时开发中也只需要实现这一个方法,除非有特别的需求

 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
     NSLog(@"UIAlertView被点击");
 }

二:UIActionSheet

步骤同样和上面一样

:创建UIActionSheet(这里显示他使用的不是show是showInView)

 UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"提示框" delegate:self cancelButtonTitle:@"删除" destructiveButtonTitle:@"更多" otherButtonTitles:@"确定", nil];
     [action showInView:self.view];

遵守的协议:  UIActionSheetDelegate

实现响应的代理方法:

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
     NSLog(@"UIActionSheet被点击");
 }

实现之后显示的界面如下

三:UIAlertController

在ios中新增了一个控制器,用来替代前面两个提示框的,不过前面两个是View,而这个是控制器,使用方法更加简单,而且可以包含前面两种。

1:创建UIAlertController着方法有两种

方法一:

 UIAlertController *alt = [[UIAlertController alloc] init];
     [alt addAction:[[UIAlertAction alloc] init]];
     [alt addAction:[UIAlertAction actionWithTitle:@"title" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
         NSLog(@"iCocos");
     }]];
     alt.title = @"klasdhgk";
     alt.message = @"alukngm";

     [self presentViewController:alt animated:YES completion:^{
         NSLog(@"iCocos");
     }];

方法二:

     UIAlertController *al = [UIAlertController alertControllerWithTitle:@"lakdhsg" message:@"adsfgh" preferredStyle:UIAlertControllerStyleAlert];

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

上面有两个地方需要注意的,

1)方法一种使用Addaction添加我们需要的项

2)presentViewController:animated:completion方法适用于弹出控制器的,在后面做项目的时候会经常用到,所以这里需要留意

四:第三方库SVProgressHUD

使用这个库之前我们需要在github上面下载这个Demo,并且将里面的需要的文件拖到我们的项目中

然后就可以直接使用了,在相应的代码处直接使用类调用久可以:

 - (IBAction)S1:(id)sender {    //直接显示
     [SVProgressHUD show];
 }

 - (IBAction)s2:(id)sender {    //显示文字(错误)
     [SVProgressHUD showErrorWithStatus:@"iCocos"];
 }

 - (IBAction)s3:(id)sender {
     //显示进度条
     [SVProgressHUD showProgress:1.0];
 }

 - (IBAction)s4:(id)sender {    //显示图片
     [SVProgressHUD showImage:[UIImage imageNamed:@"37x-Checkmark.png"] status:@"成功"];
 }

简便方法显示和隐藏

     /*
 //    [SVProgressHUD show];
 //    [SVProgressHUD showWithStatus:@"正在拼命加载"];
 //    [SVProgressHUD dismiss];

 //    [SVProgressHUD showErrorWithStatus:@"错误"];
 //    [SVProgressHUD showSuccessWithStatus:@"正确"];

     [SVProgressHUD showWithStatus:@"正在拼命加载" maskType:SVProgressHUDMaskTypeBlack];
      */

这个框架使用非常简单,但是功能不够完善,下面就介绍一个更加好用的框架MBProgressHUD

五:MBProgressHUD

这个框架相对SVPMBProgressHUD使用起来没有那么简单,但是也不会有多难,不过特可以实现更多的功能,而且如果有需要我们可以直接修改他的文件来得到我们想要的效果

在github上面下载好了之后导入这个框架

 - (IBAction)h1:(id)sender {
     //直接在View上面显示(类方法)
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 }

 - (IBAction)h2:(id)sender {
     //实例方法,直接显示
     [[MBProgressHUD alloc] show:YES];
 //    [[MBProgressHUD alloc] hide:YES];
 }

 - (IBAction)h3:(id)sender {
     //显示并且执行我们想要的代码
     [[MBProgressHUD alloc] showWhileExecuting:@selector(Runing) onTarget:self withObject:nil animated:YES];
 }
 -(void)Runing
 {
     NSLog(@"showing");
 }

我们一般实现的就是上面的几个方法,当然如果你想更加深入的学习可以直接查看文档,如果你真的闲的蛋疼的话可以自己写一套来用,也可以装装逼不是吗?

笔者简单的实现了一下(不是因为蛋疼噢)

 // 1.创建父控件
     UIView *cover = [[UIView alloc] init];
     cover.backgroundColor = [UIColor colorWithRed: green: blue: alpha:0.5];
     cover.frame = CGRectMake(, , , );
     cover.center = self.view.center;

     // 修改父控件为圆角
     cover.layer.cornerRadius = ;
     [self.view addSubview:cover];

     // 2.创建菊花
     // 菊花有默认的尺寸
     // 注意: 虽然有默认的尺寸, 但是要想显示必须让菊花转起来
     UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
     activity.center = CGPointMake(cover.frame.size.width * );
     [activity startAnimating];

     [cover addSubview:activity];
     // 3.创建UILabel
     UILabel *label = [[UILabel alloc] init];
     //    label.backgroundColor = [UIColor purpleColor];
     label.textAlignment = NSTextAlignmentCenter;
     label.text = @"正在拼命加载中...";
     label.frame = CGRectMake(, cover.frame.size.height - , cover.frame.size.width, );
     [cover addSubview:label];

/********************************Swift************************************/

笔者在做完任务之后也会偶尔写写swift,毕竟想成为大神这个必须会的,下面就是上面功能的swift实现

 /**************************UIAlertView***********************************/

     @IBAction func alert() {
         var alert:UIAlertView = UIAlertView(title: "AlertView", message: "请点击", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "确定", "其他")
         alert.show()
     }

     func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {

     }

     /**************************UIActionSheet**********************************/

     @IBAction func action() {
         var action:UIActionSheet = UIActionSheet(title: "AlertView", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "删除")
         action.showInView(self.view)
     }

     func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {

     }

     /*************************************************************/

     @IBAction func alertController1() {
         var alertController:UIAlertController = UIAlertController()

         var alacition:UIAlertAction = UIAlertAction(title: "ios", style: UIAlertActionStyle.Default, handler: nil)
         alertController.addAction(alacition)

         alertController.title = "asdgasdfg"
         alertController.message = "asdgdfsg"

         self.presentViewController(alertController, animated: true, completion: nil)

     }

     @IBAction func alertController() {
         var alertController:UIAlertController = UIAlertController(title: "laksdhfkj", message: "aslkdhfksd", preferredStyle: UIAlertControllerStyle.Alert)
         self.presentViewController(alertController, animated: true, completion: nil)
     }

注:如果你想使用更傻逼的方法也是可以的,比如使用一个控件,再用动画来控制它的出现可隐藏,不过一看就更大神差太远。。。。哈哈哈哈

iOS开发——UI篇&提示效果的更多相关文章

  1. iOS开发UI篇—CAlayer(自定义layer)

    iOS开发UI篇—CAlayer(自定义layer) 一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的Draw ...

  2. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  3. iOS开发UI篇—核心动画(基础动画)

    转自:http://www.cnblogs.com/wendingding/p/3801157.html 文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(基础动画) iOS ...

  4. iOS开发UI篇—Modal简单介绍

    iOS开发UI篇—Modal简单介绍 一.简单介绍 除了push之外,还有另外一种控制器的切换方式,那就是Modal 任何控制器都能通过Modal的形式展⽰出来 Modal的默认效果:新控制器从屏幕的 ...

  5. iOS开发UI篇—transframe属性(形变)

    iOS开发UI篇—transframe属性(形变) 1. transform属性 在OC中,通过transform属性可以修改对象的平移.缩放比例和旋转角度 常用的创建transform结构体方法分两 ...

  6. iOS开发UI篇—简单的浏览器查看程序

    iOS开发UI篇—简单的浏览器查看程序 一.程序实现要求 1.要求 2. 界面分析 (1) 需要读取或修改属性的控件需要设置属性 序号标签 图片 图片描述 左边按钮 右边按钮 (2) 需要监听响应事件 ...

  7. iOS开发UI篇—字典转模型

    iOS开发UI篇—字典转模型 一.能完成功能的“问题代码” 1.从plist中加载的数据 2.实现的代码 // // LFViewController.m // 03-应用管理 // // Creat ...

  8. iOS开发UI篇—Kvc简单介绍

    ios开发UI篇—Kvc简单介绍 一.KVC简单介绍 KVC key valued coding 键值编码 KVC通过键值间接编码 补充: 与KVC相对的时KVO,即key valued observ ...

  9. iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明

    ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明 一.tag参数 一个视图通常都只有一个父视图,多个子视图,在开发中可以通过使用子视图的tag来取出对应的子视图.方法为Viewwi ...

随机推荐

  1. poj1823,3667

    又来练线段树了…… poj1823题意很简单(明显的数据结构题),区间修改和统计最长连续空区间: 有了poj3468的基础,区间修改不是什么问题了,重点是求最长连续空区间:(弱弱的我纠结了好久) 在每 ...

  2. bzoj1196:[Hnoi2010]chorus 合唱队

    这数据范围明显的区间dp啊...然而据说二维会wa...那就写三维把... #include<cstdio> #include<cstring> #include<cct ...

  3. Reduce对Pig作业性能的影响

    Amber Zhao  Wed, Feb 25 2015 3:36 AM 很多用户在使用HDInsight的Pig功能时,发现有时很简单一个Pig Latin的relation会花费很长时间执行,当H ...

  4. Annotation介绍@interface

    Annotation是继承自java.lang.annotation.Annotation的类,用于向程序分析工具或虚拟机提供package class field methed 等方面的信息,它和其 ...

  5. 扩展类加载器-------改变JAVA的父优先类加载顺序

    java的类加载机制默认情况下是采用委托模型:当加载某个类时JVM会首先尝试用当前类加载器的父类加载器加载该类,若父类加载器加载不到再由当前类加载器来加载,因此这种模型又叫做“父优先”模型. 但是在实 ...

  6. Clear All of Them I(HDU 3920状压dp)

    题意:给有2*n个敌人的位置,枪在(0,0)位置,一次能消灭两个敌人,耗费能量为枪到一个敌人,由这个敌人再到另个敌人的的距离和,求消灭所有敌人最小耗费能量. 分析:一次枚举状态的两位即可 #inclu ...

  7. SDUT 3258 Square Number 简单数学

    和上一题一样,把平方因子除去,然后对应的数就变成固定的 #include <cstdio> #include <iostream> #include <algorithm ...

  8. Can't find file: './mysql/plugin.frm' (errno: 13)[mysql数据目录迁移错位]错误解决

    大概需要4个步骤,其中第1步通过service mysql stop停止数据库,第4步通过service mysql start启动数据库. 第2步移动数据文件,不知道是否为Ubuntu智能的原因,移 ...

  9. [selenium webdriver Java]使用自定义条件同步测试

    Selenium WebDriver可以结合ExpectedCondition类来定义自己期望的条件 创建一个新的ExpectedCondition接口,必须实现apply方法 等待元素出现 publ ...

  10. (转)Make命令简介与使用

    转载自阮一峰的博客: http://www.ruanyifeng.com/blog/2015/02/make.html 代码变成可执行文件,叫做编译(compile):先编译这个,还是先编译那个(即编 ...