一、控件
控件基類
UIWidget:所有UI控件的基類
addChild:添加UIWidget類型的節點 addRenderer:添加CCNode類型的節點
所有UIWidget,都可以設置成觸摸setTouchEnable(true)
setTouchEnable(true) addTouchEventListener(CCObject* target,SEL_TouchEvent selector):設置觸摸處理
setName:設置名字
getRect:獲取尺寸
scale9:9宮格相關東西,拼接成大圖
setScale9Enabled(true); setSize(size);
UIButton:
備注:按鈕 setPressedActionEnabled:添加按下放大動畫 addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
UITextButton
備注:按鈕,按鈕上面帶文字 setText:設置顯示內容
UICheckBox
備注:CheckBox,不解釋 addEventListenerCheckBox:選擇效果變化觸發方法
UISlider
備注:滑動條 loadBarTexture:設置背景長條紋理 loadSlidBallTextures:設置滾球紋理 loadProgressBarTexture:設置進度條紋理 addEventListenerSlider:進度變化調用,getPercent獲取值(0~100) setCapInsets(CCRectMake(0, 0, 0, 0));被設置scale9時,需要調用
UILoadingBar
備注:進度條,與滑動條的區別在於沒有滑動按鈕 setTexture:設置紋理 setPercent:設置進程(0~100) setDirection(LoadingBarTypeRight):默認從左到右 setCapInsets(CCRectMake(0, 0, 0, 0));被設置scale9時,需要調用
UILabelAtlas
備注:圖片文字控件 setProperty("1234567890", "cocosgui/labelatlas.png", 17, 22, "0")
UITextArea
備注:文字區域控件,顯示大段換行文字 setTextAreaSize:設置顯示區域 setTextHorizontalAlignment(kCCTextAlignmentCenter):設置顯示模式 setText:設置內容
UITextField
備注:輸入法控件 setPlaceHolder:設置無內容時的顯示 addEventListenerTextField:設置回調 setMaxLengthEnable:字數限制開關 setMaxLength:字數限制個數 setPasswordEnable:密碼模式開關 setPasswordStyleText(“*”):密碼顯示替代符
UILayout(panel)
備注:容器 setSize:大小 setBackGroundColorType:抹色類型(支持均勻、梯度) setBackGroundColor:抹色的色值 setClippingEnabled:圖片背景開關 setBackGroundImage:圖片 setBackGroundImageScale9Enabled:9碎片拼接開關 setBackGroundImage:9碎片紋理 setLayoutType(LAYOUT_LINEAR_VERTICAL);設置陳立方式 //陳立參數 UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create(); button->setLayoutParameter(lp1); lp1->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); lp1->setMargin(UIMargin(0, 5, 0, 10));
UIScrollView
備注:滾動容器(任意UIWidget類型)它以左上角為錨點 setBounceEnabled:彈跳開關,拉過了之后,可以彈回來 setInnerContainerSize:設置內部實際大小,必須大於等於size setDirection(SCROLLVIEW_DIR_HORIZONTAL):設置滾動方向 addChild:UIWidget都可以
UIPageView
備注:翻頁容器(必須UILayout) addPage:添加UILayout對象 getPage:獲取當前頁數 addEventListenerPageView:回調方法 case PAGEVIEW_EVENT_TURNING: UIPageView* pageView = dynamic_cast<UIPageView*>(pSender);
UIListView
備注:同UIScrollView(只能UILayout) setDirection(LISTVIEW_DIR_HORIZONTAL);:朝向 setBackGroundImageScale9Enabled:背景 setBackGroundImage:背景 addEventListenerListView:回調方法(完成初始化時,list發生變化時) initChildWithDataLength:設置數據個數 addChild:只能添加UILayout類型 getUpdateDataIndex:獲取更新的索引值 getUpdateChild:獲取更新項 setUpdateSuccess:設置更新狀態 (不用設置listView內數據的總尺寸大小)
UIDragPanel
備注:拖拽容器(任意UIWidget) setBackGroundImageScale9Enabled setBackGroundImage setBounceEnabled:彈跳開關,拉過了之后,可以彈回來 setSize:設計顯示大小 setInnerContainerSize:設置實際大小
UINodeContainer
備注:CCNode容器,與CCNode掛鈎 addCCNode:添加各種CCNode,如CCSprite addRenderer:也可以添加CCNode,每個UIWidget擁有
二、程序使用
//UI層創建 UILayer* ul = UILayer::create(); UILayout* widget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui_file/gameInfo_1.json")); Ul->addWidget(widget);
//獲取 UIImageView * lifeBar = (UIImageView *)ul->getWidgetByName("lifeBar");
//釋放 onExit或析構中需調用(否則內存泄露) GUIReader::shareReader()->purgeGUIReader(); DictionaryHelper::shareHelper()->purgeDictionaryHelper(); ActionManager::shareManager()->purgeActionManager();