2013-06-25 63 views
0

我编程方式创建一个按钮,将其添加到UIScrollView中:本身的UIButton颜色变化

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]; 

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

回答

1

请使用– setTitleColor:forState:设置你的文本颜色

+0

谢谢,它有帮助! – Sergey

0

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