iphone - 更改UIButton文本的颜色和对齐方式

标签 iphone ios ipad uibutton

我正在UIButton中创建一个UITableView:

UIButton *aboutButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[aboutButton setTitle:@"ABOUT" forState:UIControlStateNormal];
[aboutButton addTarget:self action:@selector(aboutButtonClicked) forControlEvents: UIControlEventTouchUpInside];
aboutButton.frame=CGRectMake(20, 375, 200, 35);
[tableView addSubView aboutButton];

该按钮工作正常.........但是按钮文本为蓝色并且居中对齐。我想更改文本的颜色和对齐方式-我该怎么做?

最佳答案

设置按钮标题颜色和对齐方式...

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

[aboutButton.titleLabel setTextAlignment:UITextAlignmentCenter]; 

要么
aboutButton.titleLabel.textAlignment = UITextAlignmentCenter;

要么
[aboutButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];

关于iphone - 更改UIButton文本的颜色和对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311976/

相关文章:

iphone - 如何在 MKMapView 内用彩色线连接 2 个注释?

ios - 如何在越狱的 iPhone 中使用命令 shell 卸载 iOS 应用程序

cocoa-touch - 一般 iOS 图形效率

ios - Telegram iOS 示例代码显示错误

iphone - Xcode iPhone - 要求多个文本输入然后返回它们的类

iphone - 确定 aurioTouch 示例应用程序中哪些频率对应于 x 轴

iphone - 在 Xcode 中将build设置重置为默认值?

ios - 无法将类型 '[SomeStruct]' 的值转换为指定类型 '[SomeProtocol]'

objective-c - CALayer 重绘旋转

iphone - 通过Xcode运行Iphone应用程序与通过Iphone运行它之间的区别