2013-06-25 60 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

自定義按鈕有很多狀態。有一些默認的事情會發生,但如果你想完全指定一切,那麼你還需要告訴它爲每個狀態做些什麼。 (正常,突出顯示,選中,禁用)