Sian 发表于 2014-11-21 17:55:11

MBProgressHUD的基本使用

一、基本显示效果

1、最基本的视图
    MBProgressHUD *hud = [ initWithView:self.view];
    ;
    ;

2、带文字加载视图
    MBProgressHUD *hud = [ initWithView:self.view];
    hud.labelText = @"loading...";
    ;
    ;


3、带文字加信息的视图
    MBProgressHUD *hud = [ initWithView:self.view];
    hud.labelText = @"loading...";
    hud.labelColor = ;
    hud.labelFont = ;
    hud.detailsLabelText = @"message";
    ;
    ;


4、进度指示及其他类型,通过属性progress来控制进度的完成度,取值0.0~1.0    MBProgressHUD *hud = [ initWithView:self.view];
    hud.mode = MBProgressHUDModeDeterminate;                // 圆饼扇形填充
    hud.mode = MBProgressHUDModeDeterminateHorizontalBar;   // 水平进度条
    hud.mode = MBProgressHUDModeAnnularDeterminate;         // 圆圈圆弧填充
    hud.mode = MBProgressHUDModeCustomView;   // 自定义视图
    hud.mode = MBProgressHUDModeText;         // 仅文字显示
    hud.progress = 0.3;
    ;
    ;
二、几个重要的方法
    // 添加指示器
    + (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;

    // 移除指示器
    + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;

    // 初始化视图
    - (id)initWithView:(UIView *)view;

    // 显示指示器
    - (void)show:(BOOL)animated;

    // 隐藏指示器
    - (void)hide:(BOOL)animated;

    // 显示指示器附带block代码块
    - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block;

    // 自定义队列显示指示器附带block代码块
    - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue;

    // 显示指示器附带block代码块及代码执行后的动作
    - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;

    // 自定义队列显示指示器附带block代码块及代码执行后的动作
    - (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue completionBlock:(MBProgressHUDCompletionBlock)completion;


三、几个重要的属性

// 指示器类型(菊花、进度、纯文本等共6种类型)
@property (assign) MBProgressHUDMode mode;

// 菊花颜色
@property (MB_STRONG) UIColor *activityIndicatorColor;

// 动画类型,指指示器显示或消失时的动画,有渐变、缩放等
@property (assign) MBProgressHUDAnimation animationType;

// 自定义视图,用自己的view来代替指示器上的view(菊花)
@property (MB_STRONG) UIView *customView;

// 指示器进度,在包含进度类型的指示器上使用
@property (assign) float progress;

// 主标签文本
@property (copy) NSString *labelText;

// 主标签文字字体
@property (MB_STRONG) UIFont* labelFont;

// 主标签文字颜色
@property (MB_STRONG) UIColor* labelColor;

// 副标签文本
@property (copy) NSString *detailsLabelText;

// 副标签文字字体
@property (MB_STRONG) UIFont* detailsLabelFont;

// 副标签文字颜色
@property (MB_STRONG) UIColor* detailsLabelColor;

// 指示器边缘圆角弧度,默认为10个像素
@property (assign) float cornerRadius;

// 是否显示背景蒙板,默认为NO
@property (assign) BOOL dimBackground;

// 隐藏时是否从父控件移除,默认为NO
@property (assign) BOOL removeFromSuperViewOnHide;

四、框架下载
GitHub下载
页: [1]
查看完整版本: MBProgressHUD的基本使用