UIButton *openVipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    openVipBtn.frame = CGRectMake(0, 0, 44, 44);
    [openVipBtn setTitleColor:[UIColor colorWithHexString:@"E7923A"] forState:UIControlStateNormal];
    openVipBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [openVipBtn setImage:[UIImage imageNamed:@"bookDetails_IntoVIP"] forState:UIControlStateNormal];
    openVipBtn.backgroundColor = [UIColor colorWithHexString:@"FFF7ED"];
    openVipBtn.clipsToBounds=YES;
    openVipBtn.layer.cornerRadius=15;
    [self.view addSubview:openVipBtn];

使用:

[self.view setOpenVipBtnTitle:@"VIP可免费阅读本书,开通VIP"];
- (void)setOpenVipBtnTitle:(NSString *)title
{
    [self.openVipBtn setTitle:title forState:UIControlStateNormal];
    CGFloat leftlab = [title sizeWithAttributes:@{NSFontAttributeName : self.openVipBtn.titleLabel.font}].width;
    [self.openVipBtn setImageEdgeInsets:UIEdgeInsetsMake(0, leftlab + 70, 0, 0)];
    [self.openVipBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 0)];
}

 

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-11-14
相关资源
相似解决方案