GComboBox
我们可以在编辑器编辑下拉列表的项目,也可以用代码动态设置
GComboBox combo = gcom.GetChild("n1").asComboBox;
//items是列表项目标题的数组。
combo.items = new string[] { "Item 1", "Item 2", ...};
//values是可选的,代表每个列表项目的value。
combo.values = new string[] { "value1", "value2", ...};
//获得当前选中项的索引
Debug.Log(combo.selectedIndex);
//获得当前选中项的value。
Debug.Log(combo.value);
//设置选中项,通过索引
combo.selectedIndex = 1;
//设置选中项,通过value
combo.value = "value1";
//显示选中的文本,通过text
combo.text= "哈哈哈哈";
下拉框选择改变时有通知事件:
//Unity/Cry
combo.onChanged.Add(onChanged);
//AS3
combo.addEventListener(StateChangeEvent.CHANGED, onChanged);
//Egret
combo.addEventListener(fairygui.StateChangeEvent.CHANGED, this.onChanged, this);
//Laya
combo.on(fairygui.Events.STATE_CHANGED, this, this.onChanged);
//Cocos2dx
combo->addEventListener(UIEventType::Changed, CC_CALLBACK_1(AClass::onChanged, this));
点击空白处后弹出框会自动关闭,如果要获得这个关闭的通知,可以监听移出舞台的事件,例如:
//Unity/Cry
combo.dropdown.onRemoveFromStage.Add(onPopupClosed);
//AS3
combo.dropdown.addEventListener(Event.REMOVED_FROM_STAGE, onPopupClosed);
//Egret
combo.dropdown.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onPopupClosed, this);
//Laya
combo.dropdown.on(laya.events.Event.UNDISPLAY, this, this.onPopupClosed);
//Cocos2dx
combo->getDropdown()->addEventListener(UIEventType::Exit, CC_CALLBACK_1(AClass::onPopupClosed, this));
如果要手工关闭弹出框:
GRoot.inst.HidePopup();
转载自:https://blog.csdn.net/baidu_29474379/article/details/83828402