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

Dem*_*rpl 2 xcode uibutton uiview 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];
Run Code Online (Sandbox Code Playgroud)

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

huk*_*kir 9

你想使用setTitleColor:forState:

[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)