MBProgressHUD基本用法以及扩展
作者:
找不到好的ID | 来源:发表于
2016-03-04 12:04 被阅读4336次简单用法:导入
#import "MBProgressHUD.h"
#import "ViewController.h"
遵循<MBProgressHUDDelegate>
实现MBProgressHUDDelegate方法:
- (void)hudWasHidden:(MBProgressHUD *)hud
{
[hud removeFromSuperview];
hud = nil;
}
//使用:
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.delegate = self;
hud.mode = MBProgressHUDModeText;
hud.labelText = @"正在加载数据";
//当需要消失的时候:
[hud hide:YES afterDelay:0];
// 或
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
把MBP扩展一下,方便调用,主要用于提示:
扩展名(MyMBP)
MBProgressHUD+MyMBP.h
MBProgressHUD+MyMBP.m
在MBProgressHUD+MyMBP.h中-----------:
#import "MBProgressHUD.h"
@interface MBProgressHUD (MyMBP)
+ (MBProgressHUD *)showMessage:(NSString *)message;
@end
在MBProgressHUD+MyMBP.m中-----------:
#import "MBProgressHUD+MyMBP.h"
@implementation MBProgressHUD (MyMBP)
+ (MBProgressHUD *)showMessage:(NSString *)message
{
return [self showMessage:message toView:nil];
}
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.labelText = message;
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
hud.mode = MBProgressHUDModeText;
// YES代表需要蒙版效果
//hud.dimBackground = YES;
//一秒消失
[hud hide:YES afterDelay:1];
return hud;
}
调用的时候:
[MBProgressHUD showMessage:@"加载成功了"];
本文标题:MBProgressHUD基本用法以及扩展
本文链接:https://www.haomeiwen.com/subject/fnsokttx.html
网友评论