首页 技术 正文
技术 2022年11月7日
0 收藏 710 点赞 1,161 浏览 2028 个字

理论基础

RadioButtonGroup可以把指定的单选按钮组织起来, 形成一个组, 使它们彼此交互。 在一个RadioButtonGroup, 有且只有一个或者没有RadioButton可以处于被选中状态。继承自Widget。

代码实践

RadioButtonGroup可以把指定的单选按钮组织起来, 形成一个组, 使它们彼此交互。 在一个RadioButtonGroup, 有且只有一个或者没有RadioButton可以处于被选中状态。继承自Widget。

static RadioButtonGroup * create ()
创建并返回一个RadioButtonGroup实例。

//添加删除单选按钮
virtual void addRadioButton (RadioButton *radioButton)
添加一个单选按钮到这个组。

virtual void removeRadioButton (RadioButton *radioButton)
从这组删除一个单选按钮。

virtual void removeAllRadioButtons ()
从这一组中删除所有单选按钮。

ssize_t getNumberOfRadioButtons () const
获取分组里面的单选按钮的数量.

//和选中状态有关
RadioButton * getRadioButtonByIndex (int index) const
在一组单选按钮中, 通过索引来选择。

virtual int getSelectedButtonIndex () const
获取选中单选按钮的索引。

virtual void setSelectedButton (int index)
通过索引设置一个单选按钮处于选中状态。

virtual void setSelectedButton (RadioButton *radioButton)
通过指针设置一个单选按钮处于选中状态.

virtual void setSelectedButtonWithoutEvent (int index)
通过单选按钮在组里面的索引来设置选中状态, 但是此方法不会响应事件处理

virtual void setSelectedButtonWithoutEvent (RadioButton *radioButton)
通过单选按钮的指针来设置选中状态, 但是此方法不会响应事件处理

void addEventListener (const ccRadioButtonGroupCallback &callback)
添加一个回调函数, 它将在单选按钮被选中或者取消的时候被调用.

void setAllowedNoSelection (bool allowedNoSelection)
设置一个标记允许组里面出现未选择功能。 如果它是允许的,则可以不用选择单选按钮。 如果它是不允许的,那么, 每时每刻都必须选择一个单选按钮,除了它是空的。 默认是不允许的。

bool isAllowedNoSelection () const
查询是否允许组里面存在一个都不选择的情况。

实例:

        // Create a radio button group
RadioButtonGroup* radioButtonGroup = RadioButtonGroup::create();
_uiLayer->addChild(radioButtonGroup); // Create the radio buttons
static const int NUMBER_OF_BUTTONS = ;
float startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - ) / 2.0f) * buttonWidth;
for(int i = ; i < NUMBER_OF_BUTTONS; ++i)
{
auto filePathNormal = StringUtils::format("cocosui/btn_exercise%02d_n.png", i + );
auto filePathSelected = StringUtils::format("cocosui/btn_exercise%02d_p.png", i + );
RadioButton* radioButton = RadioButton::create(filePathNormal, filePathSelected);
float posX = startPosX + buttonWidth * i;
radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f));
radioButton->setScale(BUTTON_SCALE);
radioButton->setZoomScale(0.05f);
radioButtonGroup->addRadioButton(radioButton);
_uiLayer->addChild(radioButton);
}
radioButtonGroup->setSelectedButton();
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903