ios MBProgressHUD使用以及自定义样式
2017-03-02 16:20
841 查看
使用第三方的工具类 MBProgressHUD。
实现方式如下:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"正在加载中。。。";
实现自定义视图的提示
#pragma mark - 添加提示框
-(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 *imag
4000
e = [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];
实现方式如下:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"正在加载中。。。";
实现自定义视图的提示
#pragma mark - 添加提示框
-(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 *imag
4000
e = [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];
相关文章推荐
- sencha touch 扩展篇之使用sass自定义主题样式 (下)通过css修改官方组件样式以及自定义图标
- UITabBar和UINavigation组合使用与自定义样式(iOS)----- 转
- 两行代码搞定iOS自定义HUD风格动画弹窗(支持选择记录) - SKChoosePopView的使用和实现思路
- iOS 二维码的生成,以及自定义弹框Alert,使用及demo
- iOS中使用自定义ttf/ttc字体,以及cocosbuilder中指定字体的方法
- IOS自定义系统导航栏:导航栏背景色、状态栏样式以及是否隐藏、拦截系统导航栏的返回点击事件
- iOS MBProgressHUD使用
- iOS-UITabBar的使用包括选中前后使用不同的自定义颜色以及图标颜色的改变问题)imageView,titles
- sencha touch 扩展篇之使用sass自定义主题样式 (下)通过css修改官方组件样式以及自定义图标
- IOS自定义系统导航栏:导航栏背景色、状态栏样式以及是否隐藏、拦截系统导航栏的返回点击事件
- RadioGroup以及RadioButton自定义样式的使用
- iOS 使用拖拽,在一个自定义ViewCell中显示多个cell样式
- iOS开发 自定义tableView样式(使用代码/使用Interface Builder)、分组显示、给TableView增加索引、给TableView增加SearchBar
- UITabBar和UINavigation组合使用与自定义样式(iOS)
- 自定义View以及View的属性的使用(重点,xml中定义属性的值),包括Bitmap存为jpg样式(可以模仿修改照片不喜欢的地方)
- iOS MBProgressHUD 的使用方法
- iOS 自定义导航栏使用滑动手势返回上一页 以及会遇到的BUG
- 各种Popwindow和Dialog的汇总以及仿ios的,可以自定义布局,也可以傻瓜式的代码生成,使用非常方便
- iOS GameKit蓝牙通信以及自定义cell的使用--实现仿微信聊天功能
- iOS--NSError的自定义以及使用