2014-02-12 130 views
0

我有一個UIButton以編程方式創建。未設置UIButton文本顏色

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setFrame:CGRectMake(0,0,160, 160)]; 
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal]; 
[button setTitle:@"title" forState:UIControlStateNormal]; 
button.titleLabel.font = [UIFont fontWithName:@"arial" size:20]; 
button.titleLabel.textColor = [UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1]; 

除了設置textColor之外,一切工作原理。任何想法爲什麼?

回答

1
[button setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal]; 
+0

完美 - 感謝 – RGriffiths

+0

不客氣! – plu

1

試試這個。

[button.titleLabel setFont:[UIFont fontWithName:@"arial" size:20]]; 
[button setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal];