我正在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];
按钮工作正常.........但按钮文字为蓝色并居中对齐。我想更改文本颜色和对齐方式 - 我该怎么做?
答案 0 :(得分:2)
设置按钮标题颜色&对齐......
[aboutButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[aboutButton.titleLabel setTextAlignment:UITextAlignmentCenter];
或
aboutButton.titleLabel.textAlignment = UITextAlignmentCenter;
或
[aboutButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
答案 1 :(得分:1)
[aboutButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]
[aboutButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
已在SO中多次询问
答案 2 :(得分:0)
您可以使用-[myButton setTitleColor:forState:]
来设置标题的颜色。
可以使用[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]