2

我有一个 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];

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

4

1 回答 1

9

你想使用 setTitleColor: forState:

[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
于 2012-10-18T17:19:38.470 回答