MBProgressHUD+Add.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // MBProgressHUD+Add.m
  3. // 视频客户端
  4. //
  5. // Created by mj on 13-4-18.
  6. // Copyright (c) 2013年 itcast. All rights reserved.
  7. //
  8. #import "MBProgressHUD+Add.h"
  9. @implementation MBProgressHUD (Add)
  10. #pragma mark 显示信息
  11. + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
  12. {
  13. // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  14. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  15. // 快速显示一个提示信息
  16. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  17. hud.label.text = text;
  18. // 设置图片
  19. hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
  20. // 再设置模式
  21. hud.mode = MBProgressHUDModeCustomView;
  22. CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil];
  23. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5,rect.size.width+30 ,30)];
  24. titleLabel.text = text;
  25. titleLabel.textAlignment = NSTextAlignmentCenter;
  26. titleLabel.backgroundColor = COLOR(0, 0, 0, 0.69);
  27. titleLabel.font = [UIFont systemFontOfSize:13];
  28. titleLabel.layer.cornerRadius = 15;
  29. titleLabel.layer.masksToBounds = YES;
  30. titleLabel.textColor = [UIColor whiteColor];
  31. [hud.bezelView addSubview:titleLabel];
  32. // //这里就是创建那个小人头的UIImageView,具体位置大家可以根据实际情况去设置位置
  33. //
  34. // UIImageView * customView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, -20, 74/2, 28)];
  35. //
  36. // [customView1 setImage:[UIImage imageNamed:@"[email protected]"]];
  37. //
  38. // [hud.bezelView addSubview:customView1];
  39. // 隐藏时候从父控件中移除
  40. hud.removeFromSuperViewOnHide = YES;
  41. // 1秒之后再消失
  42. [hud hideAnimated:YES afterDelay:0.7];
  43. }
  44. #pragma mark 显示错误信息
  45. + (void)showError:(NSString *)error toView:(UIView *)view{
  46. [self show:error icon:@"error.png" view:view];
  47. }
  48. + (void)showSuccess:(NSString *)success toView:(UIView *)view
  49. {
  50. [self show:success icon:@"success.png" view:view];
  51. }
  52. #pragma mark 显示一些信息
  53. + (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view {
  54. // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
  55. if (view == nil) view = [UIApplication sharedApplication].keyWindow;
  56. // 快速显示一个提示信息
  57. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  58. hud.label.text = message;
  59. // 隐藏时候从父控件中移除
  60. hud.removeFromSuperViewOnHide = YES;
  61. // YES代表需要蒙版效果
  62. // hud.dimBackground = YES;
  63. return hud;
  64. }
  65. @end