我将以下代码添加到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];
由于某种原因,按钮没有背景颜色。有什么想法吗?
答案 0 :(得分:2)
因为你没有设置颜色,只有亮度(这是“白色”在CCColor中的意思)。
尝试在初始化程序中使用颜色:
CCColor* normalColor = [CCColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0f]
[playButton setBackgroundColor:normalColor forState:CCControlStateNormal];
这会使按钮背景变为红色。