use*_*383 2 colors dynamic uibutton ios
我在xcode中添加ui按钮时使用以下代码设置标题标签的文本颜色,对齐方式和字体大小.拾取字体大小但不是文本颜色和对齐方式,为什么?谢谢.
toButton.titleLabel.textColor = [UIColor redColor];
toButton.titleLabel.textAlignment = UITextAlignmentRight;
toButton.titleLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
[toButton setTitle:fromButton.titleLabel.text forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
您要将颜色设置为titleLabel而不是此,请使用:
[toButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
对于文本对齐,此行将起作用:
toButton.titleLabel.textAlignment = UITextAlignmentRight;
Run Code Online (Sandbox Code Playgroud)
您还可以使用:
toButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6573 次 |
| 最近记录: |