MBProgressHUD基本用法以及扩展

简单用法:导入
#import "MBProgressHUD.h"
#import "ViewController.h"
遵循
实现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基本用法以及扩展)