第一步,控制器先来个属性
@property (strong, nonatomic) MBProgressHUD *HUD;
第二步,显示与隐藏的调用方法
- (void)hudTipWillShow:(BOOL)willShow{ if (willShow) { [self resignFirstResponder]; UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; if (!_HUD) { _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES]; _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar; _HUD.labelText = @"正在上传图片..."; _HUD.removeFromSuperViewOnHide = YES; }else{ _HUD.progress = 0; [keyWindow addSubview:_HUD]; [_HUD show:YES]; } }else{ [_HUD hide:YES]; } }
第三步,上传前,让其显示
[self hudTipWillShow:YES];
第四步,上传中,进度提示
if (self.HUD) { self.HUD.progress = progress;// progress是回调进度 }
第五步,上传完毕,让其隐藏
[self hudTipWillShow:NO];
来源:https://www.cnblogs.com/songxing10000/p/5003048.html