iOS 开发之设置UIButton(温故知新)

来源:互联网 发布:银行大数据是什么意思 编辑:程序博客网 时间:2024/05/17 07:52

有些时候我们想让设置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];

原创粉丝点击