博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
阅读量:4513 次
发布时间:2019-06-08

本文共 3608 字,大约阅读时间需要 12 分钟。

原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html

MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单、方便,并且可以对显示的内容进行自定义,功能很强大,很多项目中都有使用到。到GitHub上可以下载到项目源码https://github.com/jdg/MBProgressHUD,下载下来后直接把MBProgressHUD.h和MBProgressHUD.m拖入工程中就行,别忘了选择拷贝到工程。完了在需要使用的地方导入头文件就可以开始使用了。首先看下工程截图: 

提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果 
接下来是整个Demo的完整界面,这里我只选择出了几个常用的对话框,其他样式的在源码提供的Demo里可以找到,要用的话直接参考就可以。 
提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果 
接下来直接上代码了,头文件部分:

#import 
#import "MBProgressHUD.h" @interface ViewController : UIViewController { //HUD(Head-Up Display,意思是抬头显示的意思) MBProgressHUD *HUD; } - (IBAction)showTextDialog:(id)sender; - (IBAction)showProgressDialog:(id)sender; - (IBAction)showProgressDialog2:(id)sender; - (IBAction)showCustomDialog:(id)sender; - (IBAction)showAllTextDialog:(id)sender; @end

实现文件(按钮实现部分):

- (IBAction)showTextDialog:(id)sender {      //初始化进度框,置于当前的View当中      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 release];          HUD = nil;      }];  }  - (IBAction)showProgressDialog:(id)sender {      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.01f;              HUD.progress = progress;              usleep(50000);          }      } completionBlock:^{          [HUD removeFromSuperview];          [HUD release];          HUD = nil;      }];  }  - (IBAction)showProgressDialog2:(id)sender {      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.01f;              HUD.progress = progress;              usleep(50000);          }      } completionBlock:^{          [HUD removeFromSuperview];          [HUD release];          HUD = nil;      }];  }  - (IBAction)showCustomDialog:(id)sender {      HUD = [[MBProgressHUD alloc] initWithView:self.view];      [self.view addSubview:HUD];      HUD.labelText = @"操作成功";      HUD.mode = MBProgressHUDModeCustomView;      HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease];      [HUD showAnimated:YES whileExecutingBlock:^{          sleep(2);      } completionBlock:^{          [HUD removeFromSuperview];          [HUD release];          HUD = nil;      }];  }  - (IBAction)showAllTextDialog:(id)sender {      HUD = [[MBProgressHUD alloc] initWithView:self.view];      [self.view addSubview:HUD];      HUD.labelText = @"操作成功";      HUD.mode = MBProgressHUDModeText;      //指定距离中心点的X轴和Y轴的偏移量,如果不指定则在屏幕中间显示  //    HUD.yOffset = 150.0f;  //    HUD.xOffset = 100.0f;      [HUD showAnimated:YES whileExecutingBlock:^{          sleep(2);      } completionBlock:^{          [HUD removeFromSuperview];          [HUD release];          HUD = nil;      }];  }

依次实现的效果如下: 

提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果 
下面这个效果就类似中的Toast: 
提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果 
以上就简单介绍了MBProgressHUD的使用,这里都是采用block的形式来操作的,这样写起代码来更直观也更高效。

 

 

以上就是提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果的全文介绍,希望对您学习和使用ios应用开发有所帮助.

转载于:https://www.cnblogs.com/wi100sh/p/5600760.html

你可能感兴趣的文章
mac显示隐藏文件
查看>>
RobotFramework下的http接口自动化Follow Response关键字的使用
查看>>
this&super两个关键字的意义和用法
查看>>
Spring基础内容一
查看>>
鹅厂欧阳大神给年轻人的一些分享
查看>>
RocketMQ服务搭建_1
查看>>
CentOS7 安装 Docker
查看>>
Redis常见问题
查看>>
Android自带样式
查看>>
iSCSI 原理和基础使用
查看>>
Gym101350 J Lazy Physics Cat
查看>>
Java读取文件方法大全
查看>>
解决mysql无法显示中文/MySQL中文乱码问号等问题
查看>>
CentOS 7.2 配置mysql5.7
查看>>
第一次写博客用来记录自己的工程师生涯。
查看>>
python输出转义字符
查看>>
java基础43 IO流技术(输入字节流/缓冲输入字节流)
查看>>
ASP.NET那点不为人知的事(四)
查看>>
☆ [HNOI2012] 永无乡 「平衡树启发式合并」
查看>>
git 常用命令
查看>>