SelAD / DXSpinnerDemo

cocos2dx picker like ios UIPickerView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DXSpinnerDemo

cocos2dx picker like ios UIPickerView

like iOS UIPickerView

Pure c++ code

//create pSpinner = nullptr;

setSpinner(DXSpinner::spinner());//create

pSpinner->setBackGroundColor(cocos2d::Color3B::BLUE);
pSpinner->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);

pSpinner->setDelegate(this); //set delegate
pSpinner->setDataSource(this); //set datasource
pSpinner->setContentSize(cocos2d::Size(400, 200));//set size before  add to parent view

this->addChild(pSpinner); //add to view, will reload All Components

pSpinner->setPosition(cocos2d::Vec2(this->getContentSize().width/6,this->getContentSize().height/4));

pSpinner->selectRow(3, 1, true);//select row in Component

like ios UIPickerView 's Delegate //Delegate struct DXSpinnerDelegate : ProtocolBase { virtual const std::string titleForRowInComponent(DXSpinner *spinner, ssize_t row, ssize_t inComponent) = 0; //return title for row in component

virtual void didSelectRowInComponent(DXSpinner *spinner, ssize_t row, ssize_t inComponent) {}//callback when selected row changed 

};

like ios UIPickerView 's DataSource //DataSource struct DXSpinnerDataSource : ProtocolBase { virtual ssize_t numberOfComponents(DXSpinner *spinner) {return 1;};//Specifies the number of components virtual ssize_t numberOfRowsInComponent(DXSpinner *spinner, ssize_t inComponent) = 0;//Returns the number of rows for the specified component };

image

About

cocos2dx picker like ios UIPickerView


Languages

Language:C++ 70.8%Language:Objective-C 14.2%Language:C 6.7%Language:Java 3.4%Language:Objective-C++ 2.5%Language:CMake 1.2%Language:Makefile 0.3%Language:GLSL 0.3%Language:Python 0.3%Language:Shell 0.1%Language:Lua 0.1%Language:JavaScript 0.1%Language:sed 0.0%Language:Batchfile 0.0%