ios MBProgressHUD使用以及自定义样式
来源:互联网 发布:拳霸摇杆知乎 编辑:程序博客网 时间:2024/05/09 18:52
使用第三方的工具类 MBProgressHUD。
实现方式如下:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"正在加载中。。。";
实现自定义视图的提示
-(void)addHud:(NSString *)text :(UIImage *)img{
MBProgressHUD * HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.mode = MBProgressHUDModeCustomView;//自定义视图模式
UIImage *image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];//可以选择不同方式加载图片
HUD.customView = [[UIImageView alloc] initWithImage:image];
HUD.square = YES;//不知道干嘛用的
HUD.labelText =text;
[HUD showAnimated:YES whileExecutingBlock:^{
sleep(1);
} completionBlock:^{
[HUD removeFromSuperview];
}];
}
一个项目中可能要在多个页面使用,将方法提出来,写成一个公共方法
扩展mbprogresshub
在.h中
#import "MBProgressHUD.h"
@interface MBProgressHUD(Add)
+(void)showErrorWithImg:(NSString *)error :(UIImage *)img toView:(UIView *)view;
+(void)showSucessWithImg:(NSString *)sucess :(UIImage *)img toView:(UIView *)view;
@end
在.m中
#import "HubTipShow.h"
#import "MBProgressHUD.h"
@implementation MBProgressHUD(Add)
+(void)showErrorWithImg:(NSString *)error :(UIImage *)img toView:(UIView *)view{
MBProgressHUD * HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
HUD.mode = MBProgressHUDModeCustomView;
UIImage *image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
HUD.customView = [[UIImageView alloc] initWithImage:image];
HUD.square = YES;
HUD.labelText = error;
[HUD showAnimated:YES whileExecutingBlock:^{
sleep(1);
} completionBlock:^{
[HUD removeFromSuperview];
}];
}
+(void)showSucessWithImg:(NSString *)sucess :(UIImage *)img toView:(UIView *)view{
MBProgressHUD * HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
HUD.mode = MBProgressHUDModeCustomView;
UIImage *image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
HUD.customView = [[UIImageView alloc] initWithImage:image];
HUD.square = YES;
HUD.labelText = sucess;
[HUD showAnimated:YES whileExecutingBlock:^{
sleep(1);
} completionBlock:^{
[HUD removeFromSuperview];
}];
}
@end
在controller中,一句话即可解决
[MBProgressHUD showErrorWithImg:@"账号不能为空" :[UIImage imageNamed:@"errormark"] toView:self.view];
[MBProgressHUD showSucessWithImg:@“登录成功”:[UIImage imageNamed:@"Checkmark"] toView:self.view];
- ios MBProgressHUD使用以及自定义样式
- iOS 关于MBProgressHUD的使用 自定义动画
- iOS自定义对话框-MBProgressHUD
- iOS MBProgressHUD的使用
- MBProgressHUD的使用-ios
- iOS MBProgressHUD使用
- 使用MBProgressHUD自定义加载动画
- ios 指示器MBProgressHUD 的使用
- ios MBProgressHUD的基本使用
- iOS MBProgressHUD的简单使用
- iOS自定义加载等待视图-MBProgressHUD
- RadioGroup以及RadioButton自定义样式的使用
- ios MBProgressHUD
- ios MBProgressHUD
- 【IOS控件详解】之MBProgressHUD使用
- iOS开发之MBProgressHUD的使用
- iOS 第三方MBProgressHUD使用的问题
- iOS使用MBProgressHUD出现的坑
- Android studio和Eclipse分别生成jar包并混淆jar包
- 鸟哥的Linux私房菜基础篇笔记--6
- LeetCode 9. Palindrome Number
- 算法 第二章--优先队列
- PowerDesigner建立与数据库的连接,以便生成数据库和从数据库生成到PD中
- ios MBProgressHUD使用以及自定义样式
- 128. Longest Consecutive Sequence
- mybatis批量插入数据
- 常用排序算法之JavaScript实现
- CDH中Hive使用函数报错
- thinkphp3.1 DB.class.php 关于切换数据库bug问题
- iPerf 3 user documentation
- vue-loader
- PHP+Hadoop数据统计分析