UIButton颜色本身会发生变化

时间:2013-06-25 20:29:54

标签: ios uibutton

我正在以编程方式创建一个按钮并将其添加到UIScrollView:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 10, 150, 80);
[button setTitle:@"all" forState:0];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Light" size:20];
button.titleLabel.textColor = [UIColor blackColor];
button.layer.backgroundColor = [[UIColor clearColor] CGColor];
[scrolView addSubview:newGuysButon];

当我点击滚动视图时,按钮颜色从黑色变为白色。怎么会发生?

2 个答案:

答案 0 :(得分:1)

请使用– setTitleColor:forState:设置文字颜色

答案 1 :(得分:0)

自定义按钮有很多状态。有一些默认的事情会发生,但如果你想绝对指定一切,那么你还需要告诉它为每个状态做些什么。 (正常,突出显示,选中,禁用)

相关问题