2012-10-18 66 views
2

我有我做清楚交代我下面的表視圖中添加一個按鈕,一個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]; 

無論我怎麼努力,字體似乎總是變白。我能做些什麼來改變字體的顏色?

回答

9

你想用setTitleColor:forState:

[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
+0

謝謝!那樣做了! – Demasterpl