程序运行显示如下 :

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

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

第三方框架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. 解决在jenkins中无法打开robot framework report.html log.html的问题

    问题描述: Opening Robot Framework report failed Verify that you have JavaScript enabled in your browser. ...

  2. python多线程实现ping多个ip

    #!/usr/bin/env python # -*- coding:utf-8 -*- import subprocess import logging import datetime import ...

  3. dell 7559 安装Manjaro 18

    本来是装黑苹果的,折腾好几天都装好了,是可以正常使用的,可是clover始终有一个问题,每次启动前需要覆盖一遍EFI分区内EFI目录的CLOVER目录内的所有文件,方能引导MAC. 不然就卡Init ...

  4. CGI FastCGI php-FPM 分别是什么

    1.CGI协议用于php解析器跟webserver之间的通信(效率低,浪费资源) 2.FastCGI 可以一次性处理多个进程,是CGI的改良版本 3.php-FPM 是FastCGI 的进程管理器(产 ...

  5. Python2.7学习

    网上很多代码都不适用于python3版本,所以还是转回版本2来学习了 install 安装模块特别简单 E:\01_SOFT\Python27\python  -m easy_install sunb ...

  6. react图片预览插件尝试

    npm install react-zmage -S https://blog.csdn.net/Wcharles666/article/details/90262525 启动报错 直接执行  npm ...

  7. 2-set奶牛议会

    Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要的”为原则,建立了下面的投票系统: M只到场的奶牛 (1 & ...

  8. Shadows 使用说明

    1:下载最新版 Windows地址:点击下载 Mac地址:点击下载 2:Windows安装插件(点击下方插件名即可下载) .NET Framework 4.7.2和 Microsoft Visual ...

  9. QoS in RoCE

    QoS in RoCE 首页分类标签留言关于订阅2018-03-22 | 分类 Network  | 标签 RDMA  RoCE  ECN  PFC Overview TCP/IP协议栈满足不了现代I ...

  10. 实现返回顶部-wepy小程序-前端梳理

    <script type="text/javascript" src="http://hovertree.com/ziyuan/jquery/jquery-1.11 ...