1. 程式人生 > >IOS--按鈕裏面 左邊文字右邊圖片的設置

IOS--按鈕裏面 左邊文字右邊圖片的設置

err setimage nvi elf custom style hat state blog

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--按鈕裏面 左邊文字右邊圖片的設置