| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // MBProgressHUD+Add.m
- // 视频客户端
- //
- // Created by mj on 13-4-18.
- // Copyright (c) 2013年 itcast. All rights reserved.
- //
- #import "MBProgressHUD+Add.h"
- @implementation MBProgressHUD (Add)
- #pragma mark 显示信息
- + (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
- {
- // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- // 快速显示一个提示信息
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.label.text = text;
- // 设置图片
- hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
- // 再设置模式
- hud.mode = MBProgressHUDModeCustomView;
-
- CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil];
-
- UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5,rect.size.width+30 ,30)];
- titleLabel.text = text;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.backgroundColor = COLOR(0, 0, 0, 0.69);
- titleLabel.font = [UIFont systemFontOfSize:13];
- titleLabel.layer.cornerRadius = 15;
- titleLabel.layer.masksToBounds = YES;
- titleLabel.textColor = [UIColor whiteColor];
- [hud.bezelView addSubview:titleLabel];
- // //这里就是创建那个小人头的UIImageView,具体位置大家可以根据实际情况去设置位置
- //
- // UIImageView * customView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, -20, 74/2, 28)];
- //
- // [customView1 setImage:[UIImage imageNamed:@"[email protected]"]];
- //
- // [hud.bezelView addSubview:customView1];
-
- // 隐藏时候从父控件中移除
- hud.removeFromSuperViewOnHide = YES;
-
- // 1秒之后再消失
- [hud hideAnimated:YES afterDelay:0.7];
- }
- #pragma mark 显示错误信息
- + (void)showError:(NSString *)error toView:(UIView *)view{
- [self show:error icon:@"error.png" view:view];
- }
- + (void)showSuccess:(NSString *)success toView:(UIView *)view
- {
- [self show:success icon:@"success.png" view:view];
- }
- #pragma mark 显示一些信息
- + (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view {
- // if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
- if (view == nil) view = [UIApplication sharedApplication].keyWindow;
- // 快速显示一个提示信息
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
- hud.label.text = message;
- // 隐藏时候从父控件中移除
- hud.removeFromSuperViewOnHide = YES;
- // YES代表需要蒙版效果
- // hud.dimBackground = YES;
- return hud;
- }
- @end
|