cocos2d-js 控件——UIRadioButton

本文详细介绍UIRadioButton组件的使用方法,包括其公有属性、方法及回调函数。通过具体示例展示了如何创建RadioButton实例,设置不同状态下的背景图片和勾选图片,以及如何添加交互事件回调。

UIRadioButton公有属性、方法

/**
 * 状态类型
 */
enum class EventType
{
    SELECTED,
    UNSELECTED
};

/**
 * UIRadioButton回调
 */
typedef std::function<void(RadioButton* radioButton, EventType)> ccRadioButtonCallback;

/**
 * 创建一个RadioButton实例
 * @param backGround            默认状态下的背景图片
 * @param backGroundSelected    选中状态下的背景图片
 * @param cross                 选中状态下的勾选图片
 * @param backGroundDisabled    禁用状态下的背景图片
 * @param frontCrossDisabled    禁用状态下的勾选图片
 * @param texType               图片类型(Local、Plist)
 * @return RadioButton实例
 */
static RadioButton* create(const std::string& backGround,
                        const std::string& backGroundSelected,
                        const std::string& cross,
                        const std::string& backGroundDisabled,
                        const std::string& frontCrossDisabled,
                        TextureResType texType = TextureResType::LOCAL);

/**
 * 创建一个RadioButton实例
 * @param backGround        默认状态下的背景图片
 * @param cross             选中状态下的勾选图片
 * @param texType           图片类型(Local、Plist)
 * @return RadioButton实例
 */
static RadioButton* create(const std::string& backGround,
                        const std::string& cross,
                        TextureResType texType = TextureResType::LOCAL);

/**
 * 交互事件回调
 */
void addEventListener(const ccRadioButtonCallback& callback);

UIRadioButton 示例

var radio_uncheck = "btn_radio_uncheck.png";
var radio_check = "btn_radio_check.png";
var radio_croo = "btn_minus.png";
var node = new ccui.RadioButton(radio_uncheck, radio_check, radio_croo, radio_check, radio_check, ccui.Widget.PLIST_TEXTURE);
node.setAnchorPoint(0, 0);
node.setPosition(640, 360);
this.addChild(node);
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值