【发布时间】:2012-10-13 09:56:06
【问题描述】:
我创建了一个按钮。默认情况下,标题的颜色为黑色。但是当我按下它时,颜色变成了一点蓝色,并且再也没有变回来,这是怎么回事?谁能告诉我为什么?我希望按钮的标题一直保持黑色。我怎样才能做到这一点?我试过了
[button setTitleColor:[UIColor darkTextColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor darkTextColor] forState:UIControlStateSelected];
但是没有效果。当我在我的代码中添加它时,按钮的标题似乎总是蓝色的。
代码如下。
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(20, 360, 280, 44)];
[button setTitle:NSLocalizedString(@"Continue", @"Label: TextLabel in Continue button") forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
button.titleLabel.textColor = [UIColor darkTextColor];
button.titleLabel.shadowColor = [UIColor blackColor];
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:button];
[button release];
谢谢大家。我已经解决了这个问题。我认为根本原因是
button.titleLabel.textColor = [UIColor darkTextColor];
当我删除它并使用
button setTitleColor:(UIColor) forState:(UIControlState);
问题解决了!
【问题讨论】:
-
这个按钮链接到什么方法?
-
您想禁用突出显示的图像吗?在 Xib 文件中,取消选中“突出显示调整图像”。
-
目前没有实现相关方法。
-
在故事板中将按钮类型从“系统”更改为“自定义”。
标签: ios uibutton title textcolor