gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:17:22 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com