ios MBProgressHud 自定义背景 背景色 标题颜色

MBProgressHud是开发中比较常用的第三方指示器。通常包含两部分,1.网络请求的时候,显示当前网络正在请求中,请求结束后,指示器消失。无外乎就是圆形指示器,进度条指示器等等,比较常见,不多介绍。 2.就是在做一些简单的操作的时候比如关注  收藏 等等功能 成功的时候,显示一下已成功等纯文本标题。我在公司就是遇到了第二种情况。如果单单是显示纯文本那非常简单,关键是设计师设计的样式是这样子的

MBProgressHud的背景色 以及样式变成圆角的了 而且左上角还多了一个小人。这样就涉及到要修改背景的圆角,以及要在上方添加一个小人的图片。那么是如何实现这样的自定义的MBProgressHud呢?下面直接贴代码,大家可以直接拷贝,然后运行程序试一下。

先创建一个继承与NSObject的类,然后写一个+方法  我直接把+方法贴出来,然后把该头文件放到pch里,这样就可以在想用的界面直接用了。

+(void)showHint:(NSString *)hint yOffset:(float)yOffset {

    //显示提示信息

    UIView *view = [[UIApplication sharedApplication].delegate window];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

//下面的2行代码必须要写,如果不写就会导致指示器的背景永远都会有一层透明度为0.5的背景

    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;

    hud.bezelView.color = [UIColor colorWithWhite:0.f alpha:0.f];

    hud.userInteractionEnabled = NO;

//设置自定义样式的mode

    hud.mode = MBProgressHUDModeCustomView;

    CGRect rect = [hint boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil];

    hud.minSize = CGSizeMake(rect.size.width+30, 35);

    hud.bezelView.layer.masksToBounds = NO;

   

    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5,rect.size.width+30 ,30)];

    titleLabel.text = hint;

    titleLabel.textAlignment = NSTextAlignmentCenter;

    titleLabel.backgroundColor = [UIColor colorWithHexString:@"#88b6f2"];

    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:@"liujijun@2x"]];

    [hud.bezelView addSubview:customView1];

    

    

    

    

    

    hud.margin = 20.f;

    hud.yOffset = 180;

    hud.yOffset += yOffset;

    hud.removeFromSuperViewOnHide = YES;

    [hud hideAnimated:YES afterDelay:1];

}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值