我将以下代码添加到Cocos2D默认模板的IntroScene中:
CCButton *playButton = [CCButton buttonWithTitle:@"Play" fontName:@"HelveticaNeue" fontSize:18.0f];
[playButton setBackgroundColor:[CCColor colorWithWhite:0.7f alpha:1.0f] forState:CCControlStateNormal];
[playButton setBackgroundColor:[CCColor colorWithWhite:0.75f alpha:1.0f] forState:CCControlStateHighlighted];
playButton.positionType = CCPositionTypeNormalized;
playButton.position = ccp(0.5f, 0.35f);
playButton.zoomWhenHighlighted = NO;
playButton.preferredSize = CGSizeMake(222, 46);
[playButton setTarget:self selector:@selector(onSpinningClicked:)];
[self addChild:playButton];
由于某种原因,按钮没有背景色。有任何想法吗?
最佳答案
因为您没有设置颜色,所以只设置亮度(这是CCColor上下文中“白色”的含义)。
尝试在此初始值设定项中使用颜色:
CCColor* normalColor = [CCColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0f]
[playButton setBackgroundColor:normalColor forState:CCControlStateNormal];
这将使按钮背景变为红色。
关于cocos2d-iphone - Cocos2D CCButton setBackgroundColor不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22299771/