1. 程式人生 > >iOS MBProgress工具類

iOS MBProgress工具類

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,方便在其他的地方使用

我是好人,不用謝謝~~~~