有些时候我们想让UIButton的title居左对齐,我们设置
btn.textLabel.textAlignment = UITextAlignmentLeft
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离左边框保持10个像素的距离。
本文介绍如何在iOS开发中让UIButton的标题居左显示,并通过调整按钮内容的水平对齐方式解决文字紧贴边框的问题。通过设置contentHorizontalAlignment和contentEdgeInsets属性,可以实现UIButton标题的精确布局。
1089

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



