在使用自定义view时,若直接使用,如下

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.label.text = @"加载中…";
hud.mode = MBProgressHUDModeCustomView;
UIImage *image = [[UIImage imageNamed:@"toast_loading"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
hud.customView = imgView;

hud.bezelView.color = [UIColor colorWithWhite:0.0 alpha:1];
//文字颜色
hud.contentColor = [UIColor whiteColor];
hud.animationType = MBProgressHUDAnimationFade;

那么效果为

MBProgressHud添加自定义动画

若想使自定义view有动态效果,那么需要对UIImageView添加动画

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.label.text = @"加载中…";
hud.mode = MBProgressHUDModeCustomView;
UIImage *image = [[UIImage imageNamed:@"toast_loading"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anima.toValue = @(M_PI*2);
anima.duration = 1.0f;
anima.repeatCount = 10;
[imgView.layer addAnimation:anima forKey:nil];
hud.customView = imgView;

hud.bezelView.color = [UIColor colorWithWhite:0.0 alpha:1];
//文字颜色
hud.contentColor = [UIColor whiteColor];
hud.animationType = MBProgressHUDAnimationFade;

此时效果为

MBProgressHud添加自定义动画

最后补充,若想设置hud大小,可以用

hud.minSize = CGSizeMake(165,90);

 

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-08-15
  • 2021-06-02
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-09-27
  • 2022-01-06
相关资源
相似解决方案