CrossApp UIEdit(UI編輯器)

2018-09-08 15:15 更新

UI編輯器說明:

新添加CACell的布局編輯。

CATableViewCell、CACollectionViewCell和CAWaterfallViewCell都繼承CACell。

CACell可單獨(dú)使用,也可以運(yùn)用到CATableViewCell、CACollectionViewCell和CAWaterfallViewCell。


UI編輯器CACell布局使用簡單介紹:

FirstViewController.h文件:

#ifndef __HelloCpp__ViewController__
#define __HelloCpp__ViewController__
#include <iostream>
#include "CrossApp.h"
USING_NS_CC;
class FirstViewController: public CAViewController
{
     
public:
FirstViewController();
     
virtual ~FirstViewController();
     
protected:
     
    void viewDidLoad();
     
    void viewDidUnload();
     
    void onButton(CAButton* btn, DPoint point);
     
};
#endif /* defined(__HelloCpp__ViewController__) */

 FirstViewController.cpp文件:

#include "FirstViewController.h"
 
FirstViewController::FirstViewController()
{
 
}
 
FirstViewController::~FirstViewController()
{
 
}
 
void FirstViewController::viewDidLoad()
{
//    必須把新建項(xiàng)目的代碼注釋或者刪除
//    Do any additional setup after loading the view from its nib.
//    DRect winRect = this->getView()->getBounds();
//    CAImageView* imageView = CAImageView::createWithImage(CAImage::create("r/HelloWorld.png"));
//    imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop);
//    imageView->setFrame(winRect);
//    this->getView()->addSubview(imageView);
//
//    CALabel* label = CALabel::createWithCenter(DRect(winRect.size.width*0.5, winRect.size.height*0.5-270, winRect.size.width, 200));
//    label->setTextAlignment(CATextAlignmentCenter);
//    label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
//    label->setFontSize(_px(72));
//    label->setText("Hello World!");
//    label->setColor(CAColor_white);
//    this->getView()->insertSubview(label, 1);
//    
//    CCLog("%f", CAApplication::getApplication()->getWinSize().width);
     
    CACell* cell = CACell::create("cell1");
    cell->setLayout(DLayout(DHorizontalLayout_W_C(600, 0.5), DVerticalLayout_H_C(800, 0.5)));
    this->getView()->addSubview(cell);
    //以上代碼以上代碼CACell可替換成CATableViewCell、CACollectionViewCell和CAWaterfallViewCel等其中任何一種類型
     
    if(CAButton* btn = dynamic_cast<CAButton*>(cell->getViewWithID("Button_1")))
    {
        btn->addTarget(this, CAControl_selector(FirstViewController::onButton),
                       CAControlEventTouchUpInSide);
    }
}
 
void FirstViewController::viewDidUnload()
{
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
 
void FirstViewController::onButton(CAButton* btn, DPoint point)
{
    CACell* cell = CACollectionViewCell::create("cell1");
    cell->setLayout(DLayout(DHorizontalLayout_W_C(600, 0.5), DVerticalLayout_H_C(800, 0.5)));
    this->getView()->addSubview(cell);
     
    if (CAView* view = dynamic_cast<CAView*>(cell->getViewWithID("View_4")))
    {
        view->setColor(CAColor_red);
    }
}

UI編輯器Controller布局使用簡單介紹:

FirstViewController.h文件:

#ifndef __HelloCpp__ViewController__
#define __HelloCpp__ViewController__
#include <iostream>
#include "CrossApp.h"
USING_NS_CC;
class FirstViewController: public CAViewController
{
     
public:
FirstViewController();
     
virtual ~FirstViewController();
     
protected:
     
    void viewDidLoad();
     
    void viewDidUnload();
     
    void onButton(CAButton* btn, DPoint point);
     
};
#endif /* defined(__HelloCpp__ViewController__) */

FirstViewController.cpp文件:

#include "FirstViewController.h"
 
FirstViewController::FirstViewController()
{
 
}
 
FirstViewController::~FirstViewController()
{
 
}
 
void FirstViewController::viewDidLoad()
{
//    必須把新建項(xiàng)目的代碼注釋或者刪除
//    Do any additional setup after loading the view from its nib.
//    DRect winRect = this->getView()->getBounds();
//    CAImageView* imageView = CAImageView::createWithImage(CAImage::create("r/HelloWorld.png"));
//    imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop);
//    imageView->setFrame(winRect);
//    this->getView()->addSubview(imageView);
//
//    CALabel* label = CALabel::createWithCenter(DRect(winRect.size.width*0.5, winRect.size.height*0.5-270, winRect.size.width, 200));
//    label->setTextAlignment(CATextAlignmentCenter);
//    label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
//    label->setFontSize(_px(72));
//    label->setText("Hello World!");
//    label->setColor(CAColor_white);
//    this->getView()->insertSubview(label, 1);
//    
//    CCLog("%f", CAApplication::getApplication()->getWinSize().width);
     
    //需要強(qiáng)制轉(zhuǎn)換一下類型
    if(CAButton* btn = dynamic_cast<CAButton*>(this->getViewWithID("MyButton")))
    {
        btn->addTarget(this, CAControl_selector(FirstViewController::onButton),
                       CAControlEventTouchUpInSide);
    }
}
 
void FirstViewController::viewDidUnload()
{
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
 
void FirstViewController::onButton(CAButton* btn, DPoint point)
{
    if (CAView* view = getViewWithID("View_4"))
    {
        view->setColor(CAColor_magenta);
    }
}

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)