程序运行显示如下 :

点击按钮实现对应的提示框:

这里只截取了其中一张图,有兴趣的可以自己运行程序,查看其他的几种提示框哟!!!

第三方框架MBProgressHUD的下载地址:https://github.com/jdg/MBProgressHUD

程序代码如下 :

//
//  ViewController.m
//  第三方框架--提示框
//
//  Created by mac1 on 15/10/5.
//  Copyright (c) 2015年 www.iphonetrain.com. All rights reserved.
//

#import "ViewController.h"
#import "MBProgressHUD.h"

@interface ViewController ()
- (IBAction)textDialog:(id)sender;
- (IBAction)progressDialog1:(id)sender;
- (IBAction)progressDialog2:(id)sender;
- (IBAction)customDialog:(id)sender;
- (IBAction)allTextDialog:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
}

//文本提示框
- (IBAction)textDialog:(id)sender {
    
    //创建进度框
    __block MBProgressHUD *hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    
    //将当前view置于后台
    hud.dimBackground = YES;
    
    //设置对话框的文字
    hud.labelText = @"请稍等";
    
    //显示对话框
    [hud showAnimated:YES whileExecutingBlock:^{
        
        //对话框显示时需要执行的操作
        sleep(3);
        
    } completionBlock:^{
        //操作完成后执行的操作,取消显示对话框
        [hud removeFromSuperview];
        hud = nil;    //block中改变对象值,__block
        
    }];
}

//进度提示框一
- (IBAction)progressDialog1:(id)sender {
    
    //创建进度框
    __block MBProgressHUD *hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    
    hud.labelText = @"正在加载";
    
    //设置模式为进度框
    hud.mode = MBProgressHUDModeDeterminate;
    
    //显示进度框
    [hud showAnimated:YES whileExecutingBlock:^{
        
        //显示时执行的操作
        
        float progress = 0.0f;
        while (progress < 1.0f) {
            progress += 0.01;
            hud.progress = progress;
            usleep(50000);
 
        }
    } completionBlock:^{
        
        //完成后执行的操作
        [hud removeFromSuperview];
        hud = nil;
 
    }];
}

//进度提示框二
- (IBAction)progressDialog2:(id)sender {
    
    //创建进度框
    __block MBProgressHUD *hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    
    hud.labelText = @"正在加载";
    
    //设置模式为进度框
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    
    //显示进度框
    [hud showAnimated:YES whileExecutingBlock:^{
        
        //显示时执行的操作
        
        float progress = 0.0f;
        while (progress < 1.0f) {
            progress += 0.01;
            hud.progress = progress;
            usleep(50000);
            
        }
    } completionBlock:^{
        
        //完成后执行的操作
        [hud removeFromSuperview];
        hud = nil;
        
    }];
    
}

//自定义进度框
- (IBAction)customDialog:(id)sender {
    
    //创建进度框
    __block MBProgressHUD *hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    
    hud.labelText = @"操作成功";
    hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"checkmark.png"]];
    [hud showAnimated:YES whileExecutingBlock:^{
        
        //休眠2秒
        sleep(2);
        
    } completionBlock:^{
        
        [hud removeFromSuperview];
        hud = nil;
        
    }];
}

//纯文本提示框
- (IBAction)allTextDialog:(id)sender {
    
    //创建进度框
    __block MBProgressHUD *hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    
    hud.labelText = @"你操作对了哟!!!";
    hud.mode = MBProgressHUDModeText;
    
    //指定显示文本的偏移量,不指定默认显示在屏幕中间
    
    /*
    hud.xOffset = 150;
    hud.yOffset = 200;
     
     */
    [hud showAnimated:YES whileExecutingBlock:^{
        
        sleep(3);
        
    } completionBlock:^{
        
        [hud removeFromSuperview];
        hud = nil;
        
    }];
}
@end

第三方框架MBProgressHUD-----实现各种提示框的更多相关文章

  1. iOS 第三方框架-MBProgressHUD

    MBProgressHUD提示框官网地址:https://github.com/jdg/MBProgressHUD 官网里已经提供了足够多的例子供我们使用,但在实现开发中,我们用到的只是其中的一小部分 ...

  2. ios学习--第三方框架-MBProgressHUD以及扩展

    MBProgressHUD提示框官网地址:https://github.com/jdg/MBProgressHUD 一. 模式 首先, MBProgressHUD有以下几种视图模式. typedef ...

  3. js中提示框闪退问题

    当页面存在刷新  或  在线引用iframe框架时(引用框架也会导致刷新) 会导致页面加载时的弹出框闪退 解决方法:设置弹出框在页面或者框架完全加载一段时间后再弹出 <script type=& ...

  4. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  5. 【转】IOS学习笔记29—提示框第三方库之MBProgressHUD

    原文网址:http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单 ...

  6. iOS提示框,为什么你应该使用 MBProgressHUD?

    这是一篇带有一定笔者主观感情色彩的比较文章.文章着重对比github上最流行的两个iOS进度提示控件 MBProgressHUD 与 SVProgressHUD的各自优劣,来帮助初学者找到一个适合的i ...

  7. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  8. 提示框框架KVNProgress介绍

    gitHub上面有很多显示加载进度的框架,这里我们介绍一下KVNProgress框架,KVNProgress是一个可以完全定制的HUD(指示器),你可以设置加载进度的画面是否全屏,可以自己修改进度显示 ...

  9. 【开源类库学习】MBProgressHUD(提示框)

    新博客: http://www.liuchendi.com MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgre ...

随机推荐

  1. [Ynoi2017]由乃的OJ

    题意 由乃正在做她的OJ.现在她在处理OJ上的用户排名问题.OJ上注册了n个用户,编号为1-",一开始他们按照编号 排名.由乃会按照心情对这些用户做以下四种操作,修改用户的排名和编号:然而由 ...

  2. JQgrid处理json数据

    jqGrid 实例中文版网址:http://blog.mn886.net/jqGrid/国外官网:http://www.trirand.com/blog/jqgrid/jqgrid.html http ...

  3. js图片上传 的方法

    先规划出框架 <div id="AQA" style="width:300px; height:200px; background-color:aquamarine ...

  4. How To Install Docker On Ubuntu 18.04

    Docker is an increasingly popular software package that creates a container for application developm ...

  5. MongoDB 基本操作 数据库、集合

    一.数据库创建与删除 查看当前所有的数据库 show das/show databases 查看当前数据库 db 创建数据库 use hopedb db.dropDatabase()  删除当前数据库 ...

  6. yii中异步验证和自定义方法验证

    一.异步验证,一般使用ajax验证唯一性较多 1.model开启验证[['mobile_id','ip'], 'unique','message'=>Yii::t('app','E10010') ...

  7. TCP数据的传输过程

    建立连接后,两台主机就可以相互传输数据了.如下图所示: 上图给出了主机A分2次(分2个数据包)向主机B传递200字节的过程.首先,主机A通过1个数据包发送100个字节的数据,数据包的 Seq 号设置为 ...

  8. Python -三目运算(三元运算)

    if 1==1: name = "jacky" else: name = "zhuyuanlu" name = 值1 if 条件 else 值2 #如果这个条件 ...

  9. 更加方便的使用git上传自己的代码

    经过以上的培训,同学们肯定对git的基本使用没有什么问题了.但是每次代码有更改后,依旧需要 git  add  * git  commit * git   打开vim编辑器,编辑提交信息 或者 git ...

  10. ubuntu16.04安装matlab_R2018a/R2017a

    ubuntu16.04安装matlab_R2018a/R2017a 1. 文件准备 我把Matlab2018a安装镜像及破解文件放在了/home/haes/Downloads/matlab下 2.挂载 ...