xcode 更改表视图页脚中按钮的按钮文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12959145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:51:38 来源:igfitidea点击:
Change Button Text Color for Button in Footer in Table View
提问by Demasterpl
I have a UIView that I've made into a button that's added below my Table View:
我有一个 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];
No matter what I try, the font always seems to be white. What can I do to change the font's color?
无论我尝试什么,字体似乎总是白色的。我该怎么做才能改变字体的颜色?
回答by hukir
You want to use setTitleColor: forState:
你想使用 setTitleColor: forState:
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];