在表格视图中更改页脚中按钮的按钮文本颜色

时间:2012-10-18 16:17:29

标签: xcode uiview uibutton uicolor

我有一个UIView,我已将其添加到一个按钮中,该按钮已添加到我的表视图下方:

myUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120,50)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setAutoResizingMask:  [UIViewAutoResizingFlexibleWidth|UIViewAutoResizingFlexibleHeight];
[myButton setFrame:CGRectMake(20,0,80,40)];

myButton.titleLabel.textColor = [UIColor blackColor]; //Doesn't seem to work

[myButton setTitle:@"Test" forState:UIControlStateNormal];
myButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
[myButton setBackgroundImage:[[UIImage imageNamed:@"myImage.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
[myUIView addSubView:myButton];

无论我尝试什么,字体似乎总是白色的。我该怎么做才能改变字体的颜色?

1 个答案:

答案 0 :(得分:9)

您想使用setTitleColor:forState:

[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];