automovite enternetios switch controll有什么型号

1861人阅读
cocos2d-x(66)
ContolSwitch
控件起到了一个开关的作用类似于现实生活中的开关,直接上代码:
SwitchBtnScene.h
LSWGameIOS
Created by lsw on 14-10-17.
#ifndef LSWGameIOS_SwitchBtnScene_h
#define LSWGameIOS_SwitchBtnScene_h
#include &cocos2d.h&
#include &cocos-ext.h&
class SwitchBtnScene : public cocos2d::Layer
static cocos2d::Scene *createScene();
bool init();
CREATE_FUNC(SwitchBtnScene);
void valueChanged(cocos2d::Ref *sender, cocos2d::extension::Control::EventType evt);
SwitchBtnScene.cpp
LSWGameIOS
Created by lsw on 14-10-17.
#include &SwitchBtnScene.h&
#include &GUI/CCControlExtension/CCControlSwitch.h&
USING_NS_CC;
USING_NS_CC_EXT;
Scene *SwitchBtnScene::createScene()
auto scene = Scene::create();
auto layer = SwitchBtnScene::create();
scene-&addChild(layer);
bool SwitchBtnScene::init()
if (!Layer::init())
auto winSize = Director::getInstance()-&getWinSize();
auto onLabel = Label::createWithSystemFont(&on&, &Arail&, 20);
auto offLabel = Label::createWithSystemFont(&off&, &Arail&, 20);
onLabel-&setColor(Color3B(0, 0, 0));
offLabel-&setColor(Color3B(0, 0, 0));
auto maskSprite = Sprite::create(&switchButton/switchGreen.png&);
auto onSprite = Sprite::create(&switchButton/switchGreen.png&);
auto offSprite = Sprite::create(&switchButton/switchRed.png&);
auto thumbSprite = Sprite::create(&switchButton/switchBtn.png&);
//设置按钮的截取范围 开关图片和显示文字以及按钮
ControlSwitch *switchBtn = ControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel);
addChild(switchBtn);
switchBtn-&setPosition(Vec2(winSize.width/2, winSize.height/2));
//设置监听事件
switchBtn-&addTargetWithActionForControlEvents(this, cccontrol_selector(SwitchBtnScene::valueChanged), Control::EventType::VALUE_CHANGED);
void SwitchBtnScene::valueChanged(Ref *sender, Control::EventType evt)
if (evt == Control::EventType::VALUE_CHANGED)
ControlSwitch *btn = (ControlSwitch *)
if (btn-&isOn())
CCLOG(&btn is on&);
CCLOG(&btn is off&);
CCLOG(&is other state&);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:194938次
积分:2828
积分:2828
排名:第12184名
原创:74篇
转载:114篇
评论:14条
(1)(3)(4)(1)(3)(9)(11)(10)(2)(1)(1)(1)(2)(7)(46)(3)(13)(4)(6)(6)(3)(4)(14)(33)

我要回帖

更多关于 switch control 苹果 的文章

 

随机推荐