button html ios,iOS UIButton设置button上的文字和图片

这个是最后的效果图,是一个滚动选择的一个效果,因为这里之前直接放了button,后来又说要加图片,废话不多说,上代码。

241eedf12cbc?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

1-1.png

// 借款理由

for (int i = 0; i < _borrowingreasons.count; i++) {

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

btn.tag = i + 100;

btn.frame = CGRectMake(18 + 128 * i, 0, 110, 70);

[btn setTitle:_borrowingreasons[i] forState:UIControlStateNormal];

[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

btn.backgroundColor = [UIColor whiteColor];

btn.layer.cornerRadius = 4;

btn.clipsToBounds = YES;

btn.layer.borderWidth = 1;

btn.layer.borderColor = RGB(213, 213, 213).CGColor;

btn.titleLabel.font = [UIFont systemFontOfSize:15];

[btn addTarget:self action:@selector(chooseBorrowingReasons:) forControlEvents:UIControlEventTouchUpInside];

if (0 == i) {

btn.backgroundColor = RGB(251, 218, 68);

[btn addSubview:applyreasonsImageView];

[users setObject:@"付生活费" forKey:@"borrowtype"];

}

// btn's image

[btn setImage:[UIImage imageNamed:_borrowingreasons_pic[i]] forState:UIControlStateNormal];

btn.imageEdgeInsets = UIEdgeInsetsMake(-20, 43, 0, 43);

btn.titleEdgeInsets = UIEdgeInsetsMake(30, -25, 0, 0);

btn.titleLabel.textAlignment = NSTextAlignmentCenter;

[_borrowingreasonsScrollView addSubview:btn];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值