• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

CrossApp UIEdit(UI编辑器)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

UI编辑器说明:

新添加CACell的布局编辑。

CATableViewCell、CACollectionViewCell和CAWaterfallViewCell都继承CACell。

CACell可单独使用,也可以运用到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()
{
//    必须把新建项目的代码注释或者删除
//    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()
{
//    必须把新建项目的代码注释或者删除
//    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);
     
    //需要强制转换一下类型
    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);
    }
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
CAViewController(视图控制器)发布时间:2022-02-02
下一篇:
CAActivityIndicatorView(活动指示器)发布时间:2022-02-02
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap