1

I am creating a UIButton in a 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];

The button is working fine......... but the button text is in blue color and center-aligned. I want to change the text color and alignment - how do I do this?

4

3 に答える 3

2

Set button title color & Alignment ...

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

[aboutButton.titleLabel setTextAlignment:UITextAlignmentCenter]; 

or

aboutButton.titleLabel.textAlignment = UITextAlignmentCenter;

or

[aboutButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
于 2012-09-07T05:08:54.947 に答える
1
[aboutButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]
[aboutButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];

SOで何度か聞かれました

ボタンの位置合わせに関する質問

別のボタンの配置に関する質問

ボタンのタイトルの色の質問

別のボタンのタイトルの色の質問

于 2012-09-07T05:11:04.197 に答える
0

You use -[myButton setTitleColor:forState:] for setting the color of the title. The alignment can be changed with [myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]

于 2012-09-07T05:04:37.443 に答える