LHProgressHUD 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod "LHProgressHUD"
如果您之前使用过 MBProgressHUD,那么使用这些 API 将会很容易。
显示 HUD 并将其作为子视图添加,然后隐藏它
LHProgressHUD * hud = [LHProgressHUD showSuccessAddedToView:self.view animated:YES];
hud.textLabel.text = @"Loading...";
[hud hideAfterDelay:1.0 hiddenBlock:^{
NSLog(@"HUD is hidden");
}];
LHProgressHUD 有四个基本子状态
您可以使用这些函数在子状态之间切换
-(void)resetWithStatus:(NSString *)status;
-(void)showInfoWithStatus:(NSString *)status animated:(BOOL)animated;
-(void)showSuccessWithStatus:(NSString *)status animated:(BOOL)animated;
-(void)showFailureWithStatus:(NSString *)status animated:(BOOL)animated;
LHProgressHUD * hud = [LHProgressHUD showAddedToView:self.view];
hud.mode = LHProgressHUDModeTextOnly;
hud.textLabel.text = @"Loading...";
[hud hideAfterDelay:1.0];
LHProgressHUD * hud = [LHProgressHUD showAddedToView:self.view];
hud.mode = LHProgressHUDModeActivityIdenticator;
[hud hideAfterDelay:1.0];
LHProgressHUD * hud = [LHProgressHUD showAddedToView:self.view];
hud.textLabel.text = @"Loading...";
hud.spinnerColor = [UIColor whiteColor];
hud.infoColor = [UIColor orangeColor];
hud.backgroundView.blurStyle = LHBlurEffectStyleDark;
hud.centerBackgroundView.blurStyle = LHBlurEffectStyleNone;
hud.centerBackgroundView.backgroundColor = [UIColor clearColor];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[hud showSuccessWithStatus:@"Success" animated:YES];
[hud hideAfterDelay:1.0 hiddenBlock:^{
NSLog(@"HUD is hidden");
}];
});
LHProgressHUD * hud = [LHProgressHUD showAddedToView:self.view];
hud.mode = LHPRogressHUDModeGif;
hud.centerBackgroundView.blurStyle = LHBlurEffectStyleNone;
hud.centerBackgroundView.backgroundColor = [UIColor clearColor];
hud.gifImageView = [[LHGifImageView alloc] initWithGifImageName:@"gif"];
[hud hideAfterDelay:3.0];
您可以通过运行示例项目来获取更多信息
如果您懂中文,可以在我的博客上看到中文文档
Leo, [email protected]
LHProgressHUD 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。