2013-07-27 19 views
0

我嘗試了下面兩種方法來改變CCMenuItemFont的顏色,但不起作用。它總是白色的。CCMenuItemFont不能改變顏色,總是白色

CCMenuItemFont *gameItem=[CCMenuItemFont itemWithString:@"Game" target:self selector:@selector(goToPlay:)]; 
[gameItem setColor:ccGRAY]; 

gameItem.color=ccGRAY; 

什麼問題?

+0

不應該是這個樣子CCMenuItemLabel *玩= [CCMenuItemFont itemFromString:@ 「播放」 目標:自我選擇:@選擇(goToLevelSelect :)]。 play.color = ccRED; – Arbitur

+0

http://stackoverflow.com/questions/9303291/ccmenuitemfont-color-change – 2013-07-27 04:31:23

回答

0

嘗試改用CCMenuItemLabel:

CCMenuItemLabel *gameItem = [CCMenuItemFont itemWithString:@"Play" 
        target:self selector:@selector(goToPlay:)]; 
gameItem.color=ccGRAY; 
+1

initFromString已棄用,您必須使用initWithString進行初始化。 – Renaissance

+0

@ Rao27謝謝!我會編輯我的答案。 –

+0

我做了同樣的事情。但顏色仍然是白色而不是灰色! – Stella

1

CCMenuItemFontCCMenuItemLabel一個子類。實際上,我們應該設置在CCMenuItemFontCCMenuItemLabel上添加的CCLabelTTF的顏色。事實上,我們可以改變項顏色類似這樣的

CCMenuItemFont *gameItem=[CCMenuItemFont itemWithString:@"Game" target:self selector:@selector(goToPlay:)]; 
////[gameItem setColor:ccGRAY];  //No effect. 
gameItem.label.color = ccGRAY;  //Eureka. Color changed 
+0

沒錯,謝謝! – Stella

+0

@Stella。很高興幫助:) – IronMan