gpt4 book ai didi

ios - Uibutton 的 titleLabel.textColor

转载 作者:行者123 更新时间:2023-11-28 18:10:52 27 4
gpt4 key购买 nike

在 tableView 页脚我有一个按钮

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 39)];
[mainView setBackgroundColor:[UIColor clearColor]];
UIButton *themebutton= [UIButton buttonWithType:UIButtonTypeCustom];
themebutton.backgroundColor= [UIColor redColor];
[themebutton.layer setCornerRadius:5.8f];
themebutton.frame= CGRectMake(15, 0, 172, 39);
[themebutton setTitle:@"Create New" forState:UIControlStateNormal];
[themebutton setTitle:@"Create New" forState:UIControlStateSelected];
[themebutton setTitle:@"Create New" forState:UIControlStateHighlighted];
themebutton.titleLabel.font=[UIFont fontWithName:@"Raleway" size:19.8];

themebutton.titleLabel.textColor=UIColorFromRGB(0x707070);

[mainView addSubview:themebutton];
return mainView;
}

我已将 titleLabel.textColor 设置为灰色,但当我单击该按钮时,它总是将文本颜色转换为白色。为什么会发生这种情况任何人都可以帮助我。

最佳答案

需要根据状态设置颜色,例如:

[themebutton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[themebutton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];

这将显示标签为红色,按下时它将变为绿色。

关于ios - Uibutton 的 titleLabel.textColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20681307/

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