我正在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/