如下图:
UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
leftBtn.frame = CGRectMake(0, 0, 40, 35);
//<* button的的图片和文字居中 *>
leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//<* 设置title的向左偏移35 *>
[leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -35, 0, 0)];
[leftBtn setImage:[UIImage imageNamed:@"icon_homepage_downArrow"] forState:UIControlStateNormal];
leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
[leftBtn setTitle:@"上海" forState:UIControlStateNormal];
NSTextAlignmentLeft;
leftBtn.titleLabel.font = kFONT10;
按钮样式及文字布局实现
本文详细介绍了如何在iOS平台上使用UIButton实现按钮样式,并通过设置titleEdgeInsets和imageEdgeInsets来实现文字和图片的精确布局。
2万+

被折叠的 条评论
为什么被折叠?



