课程表

入门与环境搭建

简单控件的使用

视图控制

调用、存储、网络和动画

其他控件的使用

工具箱
速查手册

UI编辑器

当前位置:免费教程 » 移动开发 » CrossApp

UI编辑器说明:

  • 新添加CACell的布局编辑。
  • CATableViewCell、CACollectionViewCell和CAWaterfallViewCell都继承CACell。
  • CACell可单独使用,也可以运用到CATableViewCell、CACollectionViewCell和CAWaterfallViewCell。

UI编辑器CACell布局使用简单介绍:

FirstViewController.h文件:

  1. #ifndef __HelloCpp__ViewController__
  2. #define __HelloCpp__ViewController__
  3. #include
  4. #include "CrossApp.h"
  5. USING_NS_CC;
  6. class FirstViewController: public CAViewController
  7. {
  8. public:
  9. FirstViewController();
  10. virtual ~FirstViewController();
  11. protected:
  12. void viewDidLoad();
  13. void viewDidUnload();
  14. void onButton(CAButton* btn, DPoint point);
  15. };
  16. #endif /* defined(__HelloCpp__ViewController__) */

FirstViewController.cpp文件:

  1. #include "FirstViewController.h"
  2. FirstViewController::FirstViewController()
  3. {
  4. }
  5. FirstViewController::~FirstViewController()
  6. {
  7. }
  8. void FirstViewController::viewDidLoad()
  9. {
  10. // 必须把新建项目的代码注释或者删除
  11. // Do any additional setup after loading the view from its nib.
  12. // DRect winRect = this->getView()->getBounds();
  13. // CAImageView* imageView = CAImageView::createWithImage(CAImage::create("r/HelloWorld.png"));
  14. // imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop);
  15. // imageView->setFrame(winRect);
  16. // this->getView()->addSubview(imageView);
  17. //
  18. // CALabel* label = CALabel::createWithCenter(DRect(winRect.size.width*0.5, winRect.size.height*0.5-270, winRect.size.width, 200));
  19. // label->setTextAlignment(CATextAlignmentCenter);
  20. // label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
  21. // label->setFontSize(_px(72));
  22. // label->setText("Hello World!");
  23. // label->setColor(CAColor_white);
  24. // this->getView()->insertSubview(label, 1);
  25. //
  26. // CCLog("%f", CAApplication::getApplication()->getWinSize().width);
  27. CACell* cell = CACell::create("cell1");
  28. cell->setLayout(DLayout(DHorizontalLayout_W_C(600, 0.5), DVerticalLayout_H_C(800, 0.5)));
  29. this->getView()->addSubview(cell);
  30. //以上代码以上代码CACell可替换成CATableViewCell、CACollectionViewCell和CAWaterfallViewCel等其中任何一种类型
  31. if(CAButton* btn = dynamic_cast(cell->getViewWithID("Button_1")))
  32. {
  33. btn->addTarget(this, CAControl_selector(FirstViewController::onButton),
  34. CAControlEventTouchUpInSide);
  35. }
  36. }
  37. void FirstViewController::viewDidUnload()
  38. {
  39. // Release any retained subviews of the main view.
  40. // e.g. self.myOutlet = nil;
  41. }
  42. void FirstViewController::onButton(CAButton* btn, DPoint point)
  43. {
  44. CACell* cell = CACollectionViewCell::create("cell1");
  45. cell->setLayout(DLayout(DHorizontalLayout_W_C(600, 0.5), DVerticalLayout_H_C(800, 0.5)));
  46. this->getView()->addSubview(cell);
  47. if (CAView* view = dynamic_cast(cell->getViewWithID("View_4")))
  48. {
  49. view->setColor(CAColor_red);
  50. }
  51. }

视频演示(需要手动点击开始)

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号