有些时候我们想让设置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
本文介绍了如何设置UIButton的标题对齐方式、调整文字与边框间距及设置字体颜色的方法。通过设置contentHorizontalAlignment和contentEdgeInsets属性来实现居左对齐并保持合适的边距,同时正确设置了不同状态下的字体颜色。
5556

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



