码迷,mamicode.com
首页 > 移动开发 > 详细

IOS--按钮里面 左边文字右边图片的设置

时间:2017-10-09 17:37:01      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:lips   void   details   oid   nbsp   gre   tom   code   etop   

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)];
}

 

IOS--按钮里面 左边文字右边图片的设置

标签:lips   void   details   oid   nbsp   gre   tom   code   etop   

原文地址:http://www.cnblogs.com/qiyiyifan/p/7641780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!