UIButton 左对齐

有些时候我们想让设置UIButton的title居左对齐

btn.textLabel.textAlignment = UITextAlignmentLeft

是没有作用的,我们需要设置

btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;

但是问题又出来,此时文字会紧贴到做边框,我们可以设置

btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);

使文字距离做边框保持10个像素的距离。

=======================================================

设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:

[btn.titleLabel setTextColor:[UIColorblackColor]];

btn.titleLabel.textColor=[UIColor redColor];

而是用:

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

另外,设置按钮的图片时尽量使用setBoundgroupImage,不要使用setImage

---------------------

作者:网上的虫

来源:CSDN

原文:https://blog.csdn.net/chowbindeblog/article/details/51626411

版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(UIButton 左对齐)