Egret eui学习

eui 按钮、单选框、复选框 用法学习

        //按钮
        let button = new eui.Button();
        button.width = 100;
        button.height = 40;
        button.label = "confirm";
        //水平剧中垂直剧中
        button.horizontalCenter = 0;
        button.verticalCenter = 0;
        //button.enabled = false;
       // button.skinName = "resource/eui_skins/ButtonSkin.exml";
        this.addChild(button);

        let button2 = new eui.Button();
        button2.width = 200;
        button2.height = 100;
        button2.label = "c2";
        this.addChild(button2);

        button.addEventListener(egret.TouchEvent.TOUCH_TAP,this.btnTouchHandler,this);
        
        //egret create Hello helloEUI --type eui
        //复选框
        let cbx = new eui.CheckBox();
        cbx.label = "Select 1";
        cbx.y = 200;
        this.addChild(cbx);
        cbx.addEventListener(eui.UIEvent.CHANGE,(evt:eui.UIEvent) => {console.log(evt.target.selected);},this)
        
        //单选框-可以遍历来获取选中的value
        //RadioButtonGroup-用组来获取选中的value(需要注意的是添加group是rdb.group = radioGroup)
        let radioGroup: eui.RadioButtonGroup = new eui.RadioButtonGroup();
        radioGroup.addEventListener(eui.UIEvent.CHANGE,(evt:eui.UIEvent) => {egret.log(evt.target.selectedValue);},this);

        let rdb: eui.RadioButton = new eui.RadioButton();
        rdb.label = "Select 1";
        rdb.value = 1;
        //plan2
        rdb.group = radioGroup;
        //plan1(用的是rdb.groupName = "...")
        //rdb.groupName = "g1";
        this.addChild(rdb);
        //rdb.addEventListener(eui.UIEvent.CHANGE,(evt:eui.UIEvent) => {egret.log(evt.target.value);},this);
        let rdb2: eui.RadioButton = new eui.RadioButton();
        rdb2.label = "Select 2";
        rdb2.value = 2;
        rdb2.group = radioGroup;
        //rdb2.groupName = "g1";
        rdb2.y = 100;
        this.addChild(rdb2);

你可能感兴趣的:(Egret eui学习)