【iOS开发】---- 开源库MBProgressHUD

          MBProgressHUD是iOS中用的比较多的开源库(点此下载)。它主要是用来做提示作用的。如下图所示:



     添加MBProgressHUD到你的工程中


     有三种方法:

     使用

       初始化hud:
- (id)initWithView:(UIView *)view;
- (id)initWithWindow:(UIWindow *)window;

      如上所示,有两个方法,不过我觉得第二个和第一个是重复的,因为window本来就是一种特殊的UIView。这个方法初始化了一个MBProgressHUD(以下简称hud)。大小就是view的bounds,注意hud不是中间那个小的指示标志,而是一个大的view,包含了中间那个小的指示标识。
      除了上面两个方法,还有个类方法也可创建hud,并显示:

+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
隐藏也有个类似的方法:
+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;

      代理:

      hud有个代理方法:

/** 
 * Called after the HUD was fully hidden from the screen. 
 */
- (void)hudWasHidden:(MBProgressHUD *)hud;

      上面的解释说得很清楚了,在hud隐藏之后,就会触发这个代理方法。你可以在hud隐藏之后做需要做得事情。

      显示:

- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated;

      这个方法会在hud显示后在一个新的线程中执行后台任务(method)。

      属性

@property (copy) NSString *labelText;

      如第二张图所示“loading”提示文字。

@property (copy) NSString *detailsLabelText;

      如第三张图中所示"updating data"提示文字。
/**
 * Force the HUD dimensions to be equal if possible. 
 */
@property (assign, getter = isSquare) BOOL square;

      强制hud中间的黑色半透明指示为正方形(文本提示增加,可导致半透明指示发生形状变化)。

/** 
 * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0. 
 */
@property (assign) float progress;

      进度指示,从0到1.默认0.

/** 
 * MBProgressHUD operation mode. The default is MBProgressHUDModeIndeterminate.
 *
 * @see MBProgressHUDMode
 */
@property (assign) MBProgressHUDMode mode;

      外观模式,默认为MBProgressHUDModeIndeterminate模式。

      模式有以下几种:

typedef enum {
	/** Progress is shown using an UIActivityIndicatorView. This is the default. */
	MBProgressHUDModeIndeterminate,
	/** Progress is shown using a round, pie-chart like, progress view. */
	MBProgressHUDModeDeterminate,
	/** Progress is shown using a horizontal progress bar */
	MBProgressHUDModeDeterminateHorizontalBar,
	/** Progress is shown using a ring-shaped progress view. */
	MBProgressHUDModeAnnularDeterminate,
	/** Shows a custom view */
	MBProgressHUDModeCustomView,
	/** Shows only labels */
	MBProgressHUDModeText
} MBProgressHUDMode;

/**
 * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size).
 */
@property (assign) CGSize minSize;
      半透明指示最小尺寸。

/** 
 * Cover the HUD background view with a radial gradient. 
 */
@property (assign) BOOL dimBackground;

      背景呈现渐变梯度。

@property (MB_STRONG) UIColor *color;

      指示标志颜色。

/**
 * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views). 
 * Defaults to 20.0
 */
@property (assign) float margin;

      指示标志中元素(label,customview)与指示标志间距。

/** 
 * The y-axis offset of the HUD relative to the centre of the superview. 
 */
@property (assign) float yOffset;

      指示标志中心y坐标与父视图center的y坐标差值,即指示标志y方向偏移量。整数往下偏,反之往上。

/**
 * Removes the HUD from its parent view when hidden. 
 * Defaults to NO. 
 */
@property (assign) BOOL removeFromSuperViewOnHide;
      hud隐藏时是否从父视图移除。

      方法

- (void)show:(BOOL)animated;
- (void)hide:(BOOL)animated;
- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay;

      显示与隐藏。

      hud还支持block:

- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block;
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值