您的位置:首页 > 产品设计 > UI/UE

iOS-调整UIButton的title和image的位置

2016-07-26 11:40 447 查看
调整原生UIButton中title和image位置仅需调用此方法:

/**
*  重新布局UIbutton
*
*  @param button 所布局的UIbutton
*/
-(void)layoutBtnWithBtn:(UIButton *)button{
button.titleLabel.backgroundColor = button.backgroundColor;
button.imageView.backgroundColor = button.backgroundColor;

CGSize titleSize = button.titleLabel.bounds.size;
CGSize imageSize = button.imageView.bounds.size;
NSLog(@"titleSize :%@ \n imageSize:%@",NSStringFromCGSize(titleSize),NSStringFromCGSize(imageSize));
//文字左移
button.titleEdgeInsets = UIEdgeInsetsMake(0.0, -imageSize.width, 0.0, imageSize.width);
//图片右移
button.imageEdgeInsets = UIEdgeInsetsMake(0.0, titleSize.width, 0.0, -titleSize.width);
}


在设置UIbutton title和image的情况下,系统会自动计算文本框和图片的Frame,从而调整两者位置.

在UIbutton 调整两者位置的文章中,发现这位大神讲解的又细致又清晰,附上链接给需要的人:http://www.it610.com/article/5196532.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: