1、在.h文件中进行声明
/**!
* 启动菊花加载提示
*/
+ (void)startLoadIng;
/**!
* 关闭菊花加载提示
*/
+ (void)hideLoadIng;
+ (void)startLoadIng:(NSString *)text;
2、在.m文件中进行实现
+ (void)startLoadIng:(NSString *)text {
MBProgressHUD *HUD = (MBProgressHUD *)[[UIApplication sharedApplication].keyWindow viewWithTag:MBTAG];if (HUD == nil) {
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
HUD.tag = MBTAG;
[[UIApplication sharedApplication].keyWindow addSubview:HUD];
}
HUD.userInteractionEnabled = NO;
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = text;
HUD.labelFont = [UIFont fontWithName:@"HelveticaNeue" size:15.0f];
[HUD show:YES];
HUD.removeFromSuperViewOnHide = YES;
}
// 关闭菊花加载指示
+ (void)hideLoadIng {
MBProgressHUD *HUD = (MBProgressHUD *)[[UIApplication sharedApplication].keyWindow viewWithTag:MBTAG];
HUD.removeFromSuperViewOnHide = YES;
if (HUD != nil) {
[HUD hide:YES];
}
}
使用本方法最好是继承于NSObject,方便在其他的地方使用
我是好人,不用谢谢~~~~
本文介绍如何使用MBProgressHUD在iOS应用中显示和隐藏加载提示。包括在.h文件中声明方法及在.m文件中实现这些方法的具体步骤。
288

被折叠的 条评论
为什么被折叠?



