当前位置: 移动技术网 > IT编程>移动开发>IOS > iOS-调整UIButton的title和image的位置

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

2018年03月04日  | 移动技术网IT编程  | 我要评论

德语在线翻译器,红玉头冠,帮美女挤奶

调整原生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,从而调整两者位置.

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网