void CDNewsViewController::showAlert() { if (p_alertView) { this->getView()->removeSubview(p_alertView); p_alertView= NULL; } p_alertView = CAView::createWithFrame(this->getView()->getBounds()); this->getView()->addSubview(p_alertView); CAImageView* bg = CAImageView::createWithFrame(DRect(0,0,winSize.width,winSize.height)); bg->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); bg->setImage(CAImage::create("image/HelloWorld.png")); CAButton* btn5 = CAButton::create(CAButtonTypeSquareRect); btn5->setTag(100); btn5->setCenter(DRect(winSize.width/2, winSize.height/2, winSize.width, winSize.height)); btn5->setTitleColorForState(CAControlStateNormal,CAColor_white); btn5->setBackgroundViewForState(CAControlStateNormal, bg); btn5->setBackgroundViewForState(CAControlStateHighlighted, bg); btn5->addTarget(this, CAControl_selector(CDNewsViewController::buttonCallBack), CAControlEventTouchUpInSide); p_alertView->addSubview(btn5); CALabel* test = CALabel::createWithCenter(DRect(winSize.width/2, winSize.height-100, winSize.width, 40)); test->setColor(CAColor_gray); test->setTextAlignment(CATextAlignmentCenter); test->setVerticalTextAlignmet(CAVerticalTextAlignmentTop); test->setFontSize(_px(24)); test->setText("网络不给力,请点击屏幕重新加载~"); p_alertView->addSubview(test); }
CACollectionViewCell* AutoCollectionViewHorizontalTest::collectionCellAtIndex(CAAutoCollectionView *collectionView, const DSize& cellSize, unsigned int section, unsigned int item) { CACollectionViewCell* p_Cell = collectionView->dequeueReusableCellWithIdentifier("CrossApp"); if (p_Cell == NULL) { p_Cell = CACollectionViewCell::create("CrossApp"); CAView* itemImage = CAView::createWithLayout(DLayoutFill); itemImage->setTag(99); p_Cell->getContentView()->addSubview(itemImage); CALabel* itemText = CALabel::createWithLayout(DLayoutFill); itemText->setTag(100); itemText->setFontSize(29); itemText->setTextAlignment(CATextAlignmentCenter); itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->getContentView()->addSubview(itemText); } CAView* itemImageView = p_Cell->getContentView()->getSubviewByTag(99); itemImageView->setColor(HorizontalcolorArr.at(item)); CCLog("row = %d", item); char pos[20] = ""; sprintf(pos, "(%d,%d)", section, item); CALabel* itemText = (CALabel*)p_Cell->getContentView()->getSubviewByTag(100); itemText->setText(pos); return p_Cell; }
CAListViewCell* ListViewTest::listViewCellAtIndex(CAListView *listView, const DSize& cellSize, unsigned int index) { CAListViewCell* cell = (CAListViewCell*)listView->dequeueReusableCellWithIdentifier("ListViewCell"); if (cell==NULL) { cell = CAListViewCell::create("ListViewCell"); CALabel* test = CALabel::createWithLayout(DLayout(DHorizontalLayout_L_W(0, 200), DVerticalLayoutFill)); test->setColor(ccc4(51, 204, 255, 255)); test->setTextAlignment(CATextAlignmentCenter); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(28); test->setTag(100); cell->addSubview(test); CAButton* btn = CAButton::createWithLayout(DLayout(DHorizontalLayout_W_C(100, 0.85), DVerticalLayout_H_C(50, 0.5)), CAButtonTypeSquareRect); btn->setTitleForState(CAControlStateNormal, "btn"); btn->setTag(200); cell->addSubview(btn); btn->setTouchEventScrollHandOverToSuperview(false); } char temptext[10]; sprintf(temptext, "cell-%d",index); CALabel* test = (CALabel*)cell->getSubviewByTag(100); test->setText(temptext); return cell; }
CAView* HeroInfoController::tableViewSectionViewForHeaderInSection(CATableView* table, const CCSize& viewSize, unsigned int section) { CAView* _headView; _headView = CAView::createWithColor(COLOR_GRAY); CALabel* label = CALabel::createWithFrame(CCRect(10, 0, viewSize.width / 10, viewSize.height)); label->setTextAlignment(CATextAlignmentLeft); label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); label->setFontSize(_px(13)); _headView->addSubview(label); if (section == 0) { label->setText(UTF8ToGBK::transferToGbk("摘要")); } else if (section ==1) { label->setText(UTF8ToGBK::transferToGbk("英雄属性")); } else if (section ==2) { label->setText(UTF8ToGBK::transferToGbk("技能介绍")); } return _headView; }
void UtilManager::toast(string text, CAViewController* object) { CAApplication::getApplication()->getRootWindow()->removeSubviewByTag(TOAST_VIEW_TAG); CCSize winSize = CAApplication::getApplication()->getWinSize(); //CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3)); CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, 180 * getScale(), 30 * getScale())); back->setTag(TOAST_VIEW_TAG); back->setColor(ccc4(31, 31, 31, 200));//40 CALabel *title = CALabel::createWithCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.5), 180 * getScale(), 30 * getScale())); // title->setText(UTF8ToGBK::transferToGbk(text)); title->setText(text); //title->setText("sssss"); // title->setFontName(getChineseFont()); title->setColor(CAColor_white); title->setTextAlignment(CATextAlignmentCenter); title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); title->setFontSize(_px(15)); back->addSubview(title); //CAApplication::getApplication()->getRootWindow()->getRootViewController()->getView()->addSubview(back); back->runAction(CCFadeOut::create(1)); //CAApplication::getApplication()->getRootWindow()->addSubview(back); object->getView()->addSubview(back); //CCLog("%s", get_date_now().c_str()); scheduleOnce(schedule_selector(UtilManager::removeToast), this, TOAST_TIME); }
void SessionsViewController::showAlert() { if (p_alertView) { this->getView()->removeSubview(p_alertView); p_alertView = NULL; } p_alertView = CAView::createWithFrame(this->getView()->getBounds()); this->getView()->addSubview(p_alertView); CAImageView* bg = CAImageView::createWithFrame(DRect(_px(0), _px(120), m_winSize.width, m_winSize.height - _px(120))); bg->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); bg->setImage(CAImage::create("common/bg.png")); CAButton* btn5 = CAButton::create(CAButtonTypeSquareRect); btn5->setTag(100); btn5->setFrame(DRect(_px(0), _px(120), m_winSize.width, m_winSize.height - _px(120))); btn5->setTitleColorForState(CAControlStateNormal, CAColor_white); btn5->setBackGroundViewForState(CAControlStateNormal, bg); btn5->setBackGroundViewForState(CAControlStateHighlighted, bg); btn5->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); p_alertView->addSubview(btn5); CALabel* test = CALabel::createWithCenter(DRect(m_winSize.width / 2, (m_winSize.height - _px(120)) / 2, m_winSize.width, m_winSize.height - _px(120))); test->setColor(CAColor_gray); test->setTextAlignment(CATextAlignmentCenter); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(_px(24)); test->setText("Network cannot connected !"); p_alertView->addSubview(test); }
CAView* CAPickerView::viewForRowInComponent(int component, int row, CCSize size) { int index = m_componentsIndex[component][row]; if (index == -1) { return NULL; } CAView* view = m_dataSource->viewForRow(this, index, component); if (!view) { // create view CCString* title = m_dataSource->titleForRow(this, index, component); if (title && title->length() > 0) { CCRect rect = CCRectMake(0, 0, size.width, size.height); CALabel* label = CALabel::createWithFrame(rect); label->setText(title->getCString()); label->setColor(m_fontColorNormal); label->setFontSize(m_fontSizeNormal); label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); label->setTextAlignment(CATextAlignmentCenter); return label; } } return view; }
CAView* SecondViewController::tableViewSectionViewForHeaderInSection(CATableView* table, const CCSize& viewSize, unsigned int section) { CADipSize _viewSize = viewSize; char head[10] = ""; CAView* view = CAView::createWithColor(ccc4(239,242,243,255)); CAButton* headControl1 = CAButton::createWithCenter(CADipRect(60, _viewSize.height*0.5, 80, 80), CAButtonTypeRoundedRect); headControl1->setTag(100 + (int)section); if (sect[section] == CELL_COUNT) { headControl1->setBackGroundViewForState(CAControlStateNormal, CAImageView::createWithImage(CAImage::create("source_material/close1.png"))); } else { headControl1->setBackGroundViewForState(CAControlStateNormal, CAImageView::createWithImage(CAImage::create("source_material/open1.png"))); } headControl1->addTarget(this, CAControl_selector(SecondViewController::switchCellListInSection), CAControlEventTouchUpInSide); view->addSubview(headControl1); CALabel* header = CALabel::createWithCenter(CADipRect(_viewSize.width*0.5, _viewSize.height*0.5, 300, 50)); sprintf(head, "Section-%d", section); header->setFontSize(_px(30)); header->setText(head); header->setColor(CAColor_blueStyle); header->setTextAlignment(CATextAlignmentCenter); header->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); view->addSubview(header); return view; }
CATableViewCell* MenuViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CADipSize _size = cellSize; CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); cell->setBackgroundView(NULL); CALabel* test = CALabel::createWithCenter(CADipRect(_size.width/2+30, _size.height/2, _size.width, _size.height)); test->setColor(ccc4(220, 227, 115, 255)); test->setTextAlignment(CATextAlignmentLeft); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(_px(32)); test->setColor(CAColor_white); test->setTag(100); cell->addSubview(test); CAImageView* arrow = CAImageView::createWithCenter(CADipRect(_size.width-64,_size.height/2,64,64)); arrow->setTag(101); cell->addSubview(arrow); } CALabel* test = (CALabel*)cell->getSubviewByTag(100); test->setText(unicode_to_utf8(menuList[row]));// menuList[row]); CAImageView* arrow = (CAImageView*)cell->getSubviewByTag(101); arrow->setImage(CAImage::create("source_material/cell_btn_right.png")); return cell; }
void NoticeDetailViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* sView = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); sView->setFrame(DRect((0), (0), m_winSize.width, (120))); this->getView()->addSubview(sView); CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/nav_back.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); imageView->setFrame(DRect((20), (20), (80), (80))); button->setBackgroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(NoticeDetailViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); sView->addSubview(button); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, (70), m_winSize.width, (50))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setTouchEnabled(false); label->setFontSize((40)); label->setText("Notice"); label->setFontName(SAP_FONT_ARIAL); sView->addSubview(label); label = CALabel::createWithFrame(DRect(0, (200), m_winSize.width, (60))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray); label->setTouchEnabled(false); label->setFontSize((40)); label->setText(m_title); label->setFontName(SAP_FONT_ARIAL); this->getView()->addSubview(label); label = CALabel::createWithFrame(DRect(40, (300), m_winSize.width - 80, (800))); label->setTextAlignment(CATextAlignmentLeft); label->setColor(CAColor_gray); label->setTouchEnabled(false); label->setFontSize((30)); label->setText(m_detail); label->setFontName(SAP_FONT_ARIAL); this->getView()->addSubview(label); CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
void ButtonTest::threeButtonType(void) { CADipSize size = typeView->getBounds().size; CALabel* buttonType = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonType->setText("DefaultType"); buttonType->setFontSize(_px(30)); buttonType->setTextAlignment(CATextAlignmentCenter); buttonType->setColor(ccc4(51, 204, 255, 255)); typeView->addSubview(buttonType); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CADipRect(size.width*0.25 - 50, size.height*0.5, size.width*0.25, size.height*0.1)); defaultBtn->setTitleForState(CAControlStateNormal, "Noborder"); defaultBtn->setTitleColorForState(CAControlStateNormal, CAColor_blueStyle); typeView->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CADipRect(size.width*0.25 - 50, size.height*0.5 + 80, size.width*0.3, 50)); custom->setText("(Custom)"); custom->setFontSize(_px(20)); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(ccc4(51, 204, 255, 255)); typeView->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); squareRectBtn->setTitleForState(CAControlStateAll,"SquareRect"); typeView->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.5 + 80, size.width*0.3, 50)); square->setText("(SquareRect)"); square->setFontSize(_px(20)); square->setTextAlignment(CATextAlignmentCenter); square->setColor(CAColor_blueStyle); typeView->addSubview(square); CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect); roundedRectBtn->setCenter(CADipRect(size.width*0.75 + 50, size.height*0.5, size.width*0.25, size.height*0.1)); roundedRectBtn->setTitleForState(CAControlStateAll, "RoundedRect"); typeView->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CADipRect(size.width*0.75 + 50, size.height*0.5 + 80, size.width*0.3, 50)); rounded->setText("(RoundedRect)"); rounded->setFontSize(_px(20)); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(CAColor_blueStyle); typeView->addSubview(rounded); }
void SegmentedControlTest::viewDidLoad() { char segNormal[50] = ""; char segHighlighted[50] = ""; char segSelected[50] = ""; char pages[10] = ""; size = this->getView()->getBounds().size; CALabel* defaultStyle = CALabel::createWithCenter(CADipRect(size.width*0.5,size.height*0.05,size.width*0.5,50)); defaultStyle->setText("Default Style"); defaultStyle->setFontSize(_px(30)); defaultStyle->setColor(CAColor_blueStyle); defaultStyle->setTextAlignment(CATextAlignmentCenter); defaultStyle->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); this->getView()->addSubview(defaultStyle); CASegmentedControl* defaultSegment = CASegmentedControl::createWithCenter(CADipRect(size.width*0.5, size.height*0.15, size.width*0.8, size.height*0.1), 3); defaultSegment->setSelectedAtIndex(1); this->getView()->addSubview(defaultSegment); CCLog("%f",size.height); segment = CASegmentedControl::createWithCenter(CADipRect(size.width*0.5, size.height*0.3, size.width*0.8, size.height*0.1), 3); for (int i = 0; i < 3; i++) { sprintf(segNormal,"source_material/seg_normal%d.png",i+1); sprintf(segHighlighted,"source_material/seg_highlighted%d.png",i+1); sprintf(segSelected,"source_material/seg_selected%d.png",i+1); sprintf(pages, "Number%d", i + 1); segment->setTitleAtIndex(pages, i, CAControlStateAll); segment->setBackgroundImageAtIndex(CAImage::create(segNormal), i, CAControlStateNormal); segment->setBackgroundImageAtIndex(CAImage::create(segHighlighted), i, CAControlStateHighlighted); segment->setBackgroundImageAtIndex(CAImage::create(segSelected), i, CAControlStateSelected); } segment->setTitleColorAtIndex(CAColor_white, 0, CAControlStateAll); segment->setTitleColorAtIndex(CAColor_gray, 1, CAControlStateAll); segment->setTitleColorAtIndex(CAColor_yellow, 2, CAControlStateAll); segment->setSelectedAtIndex(1); segment->addTarget(this, CAControl_selector(SegmentedControlTest::segmentCallback)); this->getView()->addSubview(segment); defaultView = CAView::createWithColor(ccc4(150,150,150,150)); defaultView->setCenter(CADipRect(size.width*0.5, size.height*0.6 + 1, size.width*0.8, size.height*0.5)); this->getView()->addSubview(defaultView); CADipSize viewSize = defaultView->getFrame().size; defaultPage = CALabel::createWithCenter(CADipRect(viewSize.width*0.5, viewSize.height*0.5, viewSize.width*0.4, 50)); defaultPage->setText("The second page"); defaultPage->setFontSize(_px(30)); defaultPage->setColor(CAColor_white); defaultPage->setTextAlignment(CATextAlignmentCenter); defaultView->addSubview(defaultPage); }
CATableViewCell* ExchangeViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CCLog("row = %d , section = %d", row, section); CADipSize _size = cellSize; CATableViewCell* p_Cell = p_TableView->dequeueReusableCellWithIdentifier("2155"); if (p_Cell == NULL ) { p_Cell = CATableViewCell::create("2155"); p_Cell->setAllowsSelected(false); CAView* itemImage = CAView::createWithFrame(CADipRect(0, 0, _size.width, _size.height)); itemImage->setColor(ccc4(244, 243, 243, 255)); itemImage->setTag(99); p_Cell->addSubview(itemImage); CADipSize itemSize = itemImage->getBounds().size; CALabel* itemText = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/3, itemSize.width,40)); itemText->setTag(100); itemText->setFontSize(_px(35)); itemText->setTextAlignment(CATextAlignmentCenter); itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText); CALabel* itemText2 = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/5*4, itemSize.width,40)); itemText2->setTag(101); itemText2->setFontSize(_px(25)); itemText2->setTextAlignment(CATextAlignmentCenter); itemText2->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText2); CAScale9ImageView* iv = CAScale9ImageView::createWithCenter(CADipRect(itemSize.width-50,itemSize.height/2,50,50)); iv->setImage(CAImage::create("source_material/cell_btn_right.png")); iv->setTag(101); p_Cell->addSubview(iv); CAImageView* icon = CAImageView::createWithCenter(CADipRect(50,itemSize.height/2,64,64)); icon->setTag(101); icon->setScale(0.6f); icon->setImage(CAImage::create("source_material/btn_right_blue.png")); p_Cell->addSubview(icon); } CALabel * label = (CALabel*)p_Cell->getSubviewByTag(100); label->setText( unicode_to_utf8(exChangeMenuTag[row]) ); label->setColor(CAColor_black); CALabel* label2 = (CALabel*)p_Cell->getSubviewByTag(101); label2->setText(unicode_to_utf8(exChangeMenuTag2[row])); label2->setColor(CAColor_gray); return p_Cell; }
void DMClassifCatalogViewController::viewDidLoad() { CADipRect rect = this->getView()->getBounds(); rect.size.height = 96; m_uiItems = (unsigned int)(rect.size.width / 300); m_uiItems = MIN(m_uiItems, 5); m_uiItems = MAX(m_uiItems, 3); CAView* bar = CAView::createWithFrame(rect, ccc4(87, 154, 244, 255)); this->getView()->insertSubview(bar, 1); CADipRect titleRect; titleRect.origin = rect.size/2; titleRect.size.width = rect.size.width * 0.5f; titleRect.size.height = rect.size.height; CALabel* label = CALabel::createWithCenter(titleRect); label->setNumberOfLine(1); label->setFontSize(_px(32)); label->setColor(CAColor_white); label->setTextAlignment(CATextAlignmentCenter); label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); label->setText(m_sTitle); bar->addSubview(label); CCRect btnRect; btnRect.size.width = rect.size.height * 0.9f; btnRect.size.height = rect.size.height * 0.8f; btnRect.origin.x = btnRect.size.width * 0.7f; btnRect.origin.y = rect.size.height * 0.5f; CAButton* button = CAButton::createWithCenter(btnRect, CAButtonTypeCustom); button->setImageForState(CAControlStateNormal, CAImage::create("source_material/btn_left_white.png")); button->setImageColorForState(CAControlStateHighlighted, CAColor_gray); bar->addSubview(button); button->addTarget(this, CAControl_selector(DMIntroductionController::onReturn), CAControlEventTouchUpInSide); std::map<string, string> key_value; CommonHttpManager::getInstance()->send_get(get_url(HttpUrlTypeClassifCatalog, "update", m_sID, "", m_vDatas.size()), key_value, this, CommonHttpJson_selector(DMClassifCatalogViewController::onRequestFinished)); { CCRect loadingRect = this->getView()->getBounds(); loadingRect.origin.y = _px(96); loadingRect.size.height -= loadingRect.origin.y; m_pLoading = CAActivityIndicatorView::createWithFrame(loadingRect); CAImageView* indicator = CAImageView::createWithFrame(CADipRect(0, 0, 50, 50)); indicator->setImage(CAImage::create(loadingIcon)); m_pLoading->setActivityIndicatorView(indicator); CAView* bg = CAView::createWithFrame(CADipRect(0, 0, 275, 300), CAColor_clear); CAImageView* bg2 = CAImageView::createWithFrame(CADipRect(0, 0, 275, 100)); bg2->setImage(CAImage::create(loadingBackground)); bg->addSubview(bg2); m_pLoading->setActivityBackView(bg); m_pLoading->setLoadingMinTime(0.4f); m_pLoading->setColor(CAColor_white); this->getView()->insertSubview(m_pLoading, CAWindowZoderTop); m_pLoading->setTargetOnCancel(this, callfunc_selector(DMClassifCatalogViewController::initWithCollectionView)); } }
void ButtonTest::threeButtonType() { CALabel* buttonType = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.05, size.width*0.4, 50)); buttonType->setText("ButtonType"); buttonType->setFontSize(30*CROSSAPP_ADPTATION_RATIO); buttonType->setTextAlignment(CATextAlignmentCenter); buttonType->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(buttonType); CAButton* defaultBtn = CAButton::create(CAButtonTypeCustom); defaultBtn->setCenter(CCRect(size.width*0.25-50, size.height*0.15, size.width*0.2, size.height*0.05)); defaultBtn->setTitleForState(CAControlStateNormal, "Noborder"); defaultBtn->setTitleColorForState(CAControlStateNormal, ccc4(51, 204, 255, 255)); this->getView()->addSubview(defaultBtn); CALabel* custom = CALabel::createWithCenter(CCRect(size.width*0.25-50, size.height*0.15+80, size.width*0.2, 50)); custom->setText("(CAButtonTypeCustom)"); custom->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); custom->setTextAlignment(CATextAlignmentCenter); custom->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(custom); CAButton* squareRectBtn = CAButton::create(CAButtonTypeSquareRect); squareRectBtn->setCenter(CCRect(size.width*0.5, size.height*0.15, size.width*0.2, size.height*0.05)); this->getView()->addSubview(squareRectBtn); CALabel* square = CALabel::createWithCenter(CCRect(size.width*0.5, size.height*0.15 + 80, size.width*0.2, 50)); square->setText("(CAButtonTypeSquareRect)"); square->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); square->setTextAlignment(CATextAlignmentCenter); square->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(square); CAButton* roundedRectBtn = CAButton::create(CAButtonTypeRoundedRect); roundedRectBtn->setCenter(CCRect(size.width*0.75 + 50, size.height*0.15, size.width*0.2, size.height*0.05)); this->getView()->addSubview(roundedRectBtn); CALabel* rounded = CALabel::createWithCenter(CCRect(size.width*0.75+50, size.height*0.15 + 80, size.width*0.2, 50)); rounded->setText("(CAButtonTypeRoundedRect)"); rounded->setFontSize(20 * CROSSAPP_ADPTATION_RATIO); rounded->setTextAlignment(CATextAlignmentCenter); rounded->setColor(ccc4(51, 204, 255, 255)); this->getView()->addSubview(rounded); }
void ECollectionViewHorizontalCell::initWithCell() { CALabel* test = CALabel::createWithLayout(DLayoutFill); test->setColor(ccc4(34, 151, 254, 255)); test->setTextAlignment(CATextAlignmentCenter); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(28); test->setTag(100); this->addSubview(test); }
void SessionsViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* sView = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); sView->setFrame(DRect((0), (0), m_winSize.width, (120))); this->getView()->addSubview(sView); CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("common/nav_search.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackgroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); FSegmentView* seg = FSegmentView::createWithFrame(DRect(m_winSize.width - 240, 45, 200, 50), 2); seg->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); imageView = CAImageView::createWithImage(CAImage::create("common/nav_time.png")); seg->setItemBackgroundImage(imageView, 0); imageView = CAImageView::createWithImage(CAImage::create("common/nav_type.png")); seg->setItemBackgroundImage(imageView, 1); seg->setTag(200, 0); seg->setTag(201, 1); this->getView()->addSubview(seg); m_navType = 0; m_navTimeType = 0; m_navFormatType = 0; CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, (75), m_winSize.width, (50))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setFontSize(SAP_TITLE_FONT_SIZE); label->setText("Agenda"); label->setFontName(SAP_FONT_ARIAL); sView->addSubview(label); if (m_msg->empty()) { requestMsg(); { p_pLoading = CAActivityIndicatorView::createWithCenter(DRect(m_winSize.width / 2, m_winSize.height / 2, 50, 50)); this->getView()->insertSubview(p_pLoading, CAWindowZOderTop); p_pLoading->setLoadingMinTime(0.5f); p_pLoading->setTargetOnCancel(this, callfunc_selector(SessionsViewController::initMsgTableView)); } } else { initMsgTableView(); } CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
void CANavigationBar::showTitle() { CCRect rect; rect.origin = this->getBounds().size/2; rect.size.height = this->getBounds().size.height; rect.size.width = this->getBounds().size.width - rect.size.height * 4; if (m_pTitle) { this->removeSubview(m_pTitle); m_pTitle = NULL; } if (CAView* titleView = m_pItem->getTitleView()) { float aspectRatio = 0; if (!titleView->getFrame().size.equals(CCSizeZero)) { aspectRatio = titleView->getFrame().size.width / titleView->getFrame().size.height; } rect.size.height *= 2/3.0f; rect.size.width = aspectRatio < FLT_EPSILON ? rect.size.width : aspectRatio * rect.size.height; titleView->setCenter(rect); this->addSubview(titleView); m_pTitle = titleView; } else if (CAImage* image = m_pItem->getTitleViewImage()) { float height = MIN(image->getContentSize().height, rect.size.height * 0.75f); float width = height * image->getContentSize().width / image->getContentSize().height; width = MIN(rect.size.width, width); rect.size = CCSize(width, height); m_pTitle = CAImageView::createWithImage(image); m_pTitle->setCenter(rect); this->addSubview(m_pTitle); } else { CALabel* title = CALabel::createWithCenter(rect); title->setTextAlignment(CATextAlignmentCenter); title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); title->setNumberOfLine(1); title->setColor(m_cTitleColor); title->setFontSize(_px(32)); this->addSubview(title); m_pTitle = title; if (m_pItem) { std::string str = m_pItem->getTitle(); ((CALabel*)m_pTitle)->setText(str.c_str()); } } }
void ContactViewController::viewDidLoad() { //this->getNavigationController()->setTitle("联系我"); CADipSize __winSize = this->getView()->getBounds().size; CALabel *lable = CALabel::createWithFrame(CADipRect(0,0,__winSize.width,__winSize.height)); lable->setText("如有任何问题请联系我。QQ:254069025,邮箱:[email protected] .帮本人介绍对象者,事成之后有重谢^_^"); lable->setTextAlignment(CATextAlignmentCenter); lable->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); lable->setFontSize(_px(40)); this->getView()->addSubview(lable); }
void ProductCommentViewController::viewDidLoad() { CANavigationBarItem* item = CANavigationBarItem::create(CN_STRING("shangpinpinglun")); this->setNavigationBarItem(item); CCSize size = this->getView()->getBounds().size; CALabel *pLabel = CALabel::createWithCenter(CCRect(size.width / 2, size.height / 2, _px(500), _px(40))); pLabel->setTextAlignment(CATextAlignmentCenter); pLabel->setText(CN_STRING("haimeiyouliuyanyo")); pLabel->setFontSize(_px(40)); pLabel->setColor(MiniColor_font1); this->getView()->addSubview(pLabel); }
void ThirdViewController::viewDidLoad() { CCRect rect = this->getView()->getBounds(); CCRect tableRect = rect; m_pCollectionView = new CACollectionView(); m_pCollectionView->initWithFrame(tableRect); m_pCollectionView->setCollectionViewDataSource(this); m_pCollectionView->setCollectionViewDelegate(this); this->getView()->addSubview(m_pCollectionView); m_pCollectionView->release(); m_pCollectionView->setBackGroundColor(CAColor_gray); CAView* headView = CAView::createWithColor(CAColor_red); CCSize sz = CCSize(rect.size.width, 100); CALabel* pLabel = new CALabel(); pLabel->initWithCenter(CCRectMake(sz.width / 2, sz.height / 2, sz.width, sz.height)); pLabel->setTextAlignment(CATextAlignmentCenter); pLabel->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); pLabel->setText("CollectionView"); pLabel->setFontName("fonts/arial.ttf"); pLabel->setFontSize(36); pLabel->setColor(CAColor_white); headView->addSubview(pLabel); pLabel->release(); m_pCollectionView->setCollectionHeaderView(headView); m_pCollectionView->setCollectionHeaderHeight(100); CAView* footerView = CAView::createWithColor(CAColor_blue); CALabel* pLabel2 = new CALabel(); pLabel2->initWithCenter(CCRectMake(sz.width / 2, sz.height / 2, sz.width, sz.height)); pLabel2->setTextAlignment(CATextAlignmentCenter); pLabel2->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); pLabel2->setText("Footer View"); pLabel2->setFontName("fonts/arial.ttf"); pLabel2->setFontSize(28); pLabel2->setColor(CAColor_gray); footerView->addSubview(pLabel2); pLabel2->release(); m_pCollectionView->setCollectionFooterView(footerView); m_pCollectionView->setCollectionFooterHeight(100); m_pCollectionView->setAllowsSelection(true); }
void SessionsViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; CAScale9ImageView* sView = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); sView->setFrame(DRect(_px(0), _px(0), m_winSize.width, _px(120))); this->getView()->addSubview(sView); CAButton* button = CAButton::createWithFrame(DRect(_px(20), _px(20), _px(100), _px(100)), CAButtonTypeCustom); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_notification.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); m_timeNoticeImageView = CAImageView::createWithFrame(DRect(_px(60), _px(30), _px(10), _px(10))); m_timeNoticeImageView->setImage(CAImage::create("common/reddot.png")); button->addSubview(m_timeNoticeImageView); button = CAButton::createWithFrame(DRect(m_winSize.width - _px(120), _px(20), _px(100), _px(100)), CAButtonTypeCustom); imageView = CAImageView::createWithImage(CAImage::create("main/nav_prize.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); button->addTarget(this, CAControl_selector(SessionsViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(30); this->getView()->addSubview(button); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, _px(70), m_winSize.width, _px(40))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setFontSize(_px(40)); label->setText("Agenda"); label->setFontName("fonts/arial.ttf"); sView->addSubview(label); if (m_msg.empty()) { requestMsg(); } else { this->initMsgTableView(); } CCLog("%f", CAApplication::getApplication()->getWinSize().width); }
void ButtonTest::buttonTouchEvent(void) { CADipSize size = eventView->getBounds().size; CALabel* buttonTouch = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.2, size.width*0.4, 50)); buttonTouch->setText("TouchEvent"); buttonTouch->setFontSize(_px(35)); buttonTouch->setTextAlignment(CATextAlignmentCenter); buttonTouch->setColor(CAColor_blueStyle); eventView->addSubview(buttonTouch); CAButton* btnOne = CAButton::create(CAButtonTypeCustom); btnOne->setCenter(CADipRect(size.width*0.25 - 50, size.height*0.5, size.width*0.25, size.height*0.1)); btnOne->setTag(BUTTONONE); btnOne->setTitleForState(CAControlStateAll, "TouchDown"); btnOne->setTitleColorForState(CAControlStateNormal, CAColor_blueStyle); btnOne->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/round1.png"))); btnOne->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/round2.png"))); btnOne->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchDown); eventView->addSubview(btnOne); CAButton* btnTwo = CAButton::create(CAButtonTypeSquareRect); btnTwo->setCenter(CADipRect(size.width*0.5, size.height*0.5, size.width*0.25, size.height*0.1)); btnTwo->setTag(BUTTONTWO); btnTwo->setTitleForState(CAControlStateAll, "TouchMoved"); btnTwo->setTitleColorForState(CAControlStateNormal,CAColor_white); btnTwo->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_square_highlighted.png"))); btnTwo->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_square_selected.png"))); btnTwo->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchMoved); eventView->addSubview(btnTwo); CAButton* btnThree = CAButton::create(CAButtonTypeRoundedRect); btnThree->setCenter(CADipRect(size.width*0.75 + 50, size.height*0.5, size.width*0.25, size.height*0.1)); btnThree->setTag(BUTTONTHREE); btnThree->setTitleForState(CAControlStateAll, "TouchUpInSide"); btnThree->setTitleColorForState(CAControlStateNormal, CAColor_white); btnThree->setBackGroundViewForState(CAControlStateNormal, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_highlighted.png"))); btnThree->setBackGroundViewForState(CAControlStateHighlighted, CAScale9ImageView::createWithImage(CAImage::create("source_material/btn_rounded3D_selected.png"))); btnThree->addTarget(this, CAControl_selector(ButtonTest::buttonCallback), CAControlEventTouchUpInSide); eventView->addSubview(btnThree); descTest = CALabel::createWithCenter(CADipRect(size.width*0.5, size.height*0.8, size.width, 50)); descTest->setText("Display coordinates"); descTest->setFontSize(_px(30)); descTest->setColor(CAColor_blueStyle); descTest->setTextAlignment(CATextAlignmentCenter); eventView->addSubview(descTest); }
void UtilManager::toast(string text, string image, bool isSmall) { CAApplication::getApplication()->getRootWindow()->removeSubviewByTag(TOAST_VIEW_TAG); CCSize winSize = CAApplication::getApplication()->getWinSize(); CAImageView *back = CAImageView::create(); if (isSmall == false) { //CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3)); back->setCenter(CCRect(winSize.width*0.5, winSize.height*0.55, _px(120), _px(120))); } else { back->setCenter(CCRect(winSize.width*0.5, winSize.height*0.4, _px(120), _px(120))); } back->setTag(TOAST_VIEW_TAG); back->setImage(CAImage::create("image/scape_storage.png")); //back->setColor(ccc4(31, 31, 31, 200));//40 CALabel *title = CALabel::createWithCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.8), 100, 100)); //title->setText(UTF8ToGBK::transferToGbk(text)); //title->setFontName(getChineseFont()); title->setColor(CAColor_white); title->setTextAlignment(CATextAlignmentCenter); title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); title->setFontSize(_px(22)); back->addSubview(title); CAImageView *icon = CAImageView::create(); if (isSmall == false) { //CAView *back = CAView::createWithCenter(CCRect(winSize.width*0.5, winSize.height*0.5, _dip(winSize.width)*0.3, _dip(winSize.height)*0.3)); icon->setCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.4), 90 / 1.5, 68 / 1.5)); } else { icon->setCenter(CADipRect(_dip(back->getBounds().size.width*0.5), _dip(back->getBounds().size.height*0.4), 72 / 1.5, 72 / 1.5)); } //CAImageView *icon = CAImageView::createWithCenter(CADipRect(_dip(back->getBounds().size.width*0.5),_dip(back->getBounds().size.height*0.4), 105/1.5, 95/1.5)); icon->setImage(CAImage::create(image)); back->addSubview(icon); CAApplication::getApplication()->getRootWindow()->addSubview(back); //CCLog("%s", get_date_now().c_str()); icon->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(0.3), CCFadeOut::create(TOAST_TIME / 2.0))); back->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(0.3), CCFadeOut::create(TOAST_TIME))); scheduleOnce(schedule_selector(UtilManager::removeToast), this, TOAST_TIME); }
CAView* RecipeListViewController::tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section) { std::string head = m_strSectionTitle; CAView* view = CAView::createWithColor(SectionTitleColor); DSize _size = viewSize; CALabel* header = CALabel::createWithLayout(DLayout(DHorizontalLayout_L_R(0,0), DVerticalLayoutFill)); header->setText(head); header->setFontSize(30); header->setColor(CAColor_white); header->setTextAlignment(CATextAlignmentCenter); header->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); view->addSubview(header); return view; }
CAView* MainViewController::tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section) { CAView* view = NULL; if(m_filterMsg.empty()) { // lable view = CAView::createWithFrame(DRect(0, 0, m_winSize.width, m_winSize.height)); CALabel* label = CALabel::createWithCenter(DRect((m_winSize.width / 2), (120), (640 - 80), (240))); label->setText("My following sessions. (Avaliable on 2nd March)"); label->setFontSize((30)); label->setColor(ccc4(0, 0xa8, 0xfc, 0xff)); label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); label->setTextAlignment(CATextAlignmentCenter); view->addSubview(label); } return view; }
CACollectionViewCell* CDUIShowCollectionView::collectionCellAtIndex(CACollectionView *collectionView, const CCSize& cellSize, unsigned int section, unsigned int row, unsigned int item) { if (row * 3 + item >= m_vTitle.size()) { return NULL; } CADipSize _size = cellSize; CACollectionViewCell* p_Cell = collectionView->dequeueReusableCellWithIdentifier("CrossApp"); if (p_Cell == NULL) { p_Cell = CACollectionViewCell::create("CrossApp"); p_Cell->setAllowsSelected(false); CAView* itemImage = CAView::createWithFrame(CADipRect(0, 0, _size.width, _size.height)); itemImage->setTag(99); p_Cell->addSubview(itemImage); CADipSize itemSize = itemImage->getBounds().size; CALabel* itemText = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height-40, itemSize.width,40)); itemText->setTag(100); itemText->setFontSize(_px(24)); itemText->setTextAlignment(CATextAlignmentCenter); itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText); CAImageView* icon = CAImageView::createWithCenter(CADipRect(itemSize.width/2,itemSize.height/3,189,123)); icon->setTag(101); icon->setScale(0.6f); p_Cell->addSubview(icon); } CAView* itemImageView = p_Cell->getSubviewByTag(99); itemImageView->setColor(ccc4(244, 243, 243, 255)); int index = row * 3 + item; CALabel* itemText = (CALabel*)p_Cell->getSubviewByTag(100); itemText->setText(m_vTitle.at(index)); itemText->setColor(ccc4(34,151,254,255)); CAImageView* icon = (CAImageView*)p_Cell->getSubviewByTag(101); icon->setImage(CAImage::create(iconTag[index])); return p_Cell; }
void MyTableViewCell::initCell() { CADipSize cellSize = this->getFrame().size; CALabel* cellText = CALabel::createWithCenter(CADipRect(cellSize.width*0.1, cellSize.height*0.5, cellSize.width*0.3, cellSize.height*0.8)); cellText->setTag(100); cellText->setFontSize(30 * CROSSAPP_ADPTATION_RATIO); cellText->setColor(CAColor_blueStyle); cellText->setTextAlignment(CATextAlignmentCenter); cellText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); this->addSubview(cellText); CAButton* cellBtn = CAButton::createWithCenter(CADipRect(cellSize.width*0.8, cellSize.height*0.5, cellSize.width*0.2, cellSize.height*0.5), CAButtonTypeRoundedRect); cellBtn->setTag(102); cellBtn->setTitleForState(CAControlStateAll, "Touch"); cellBtn->addTarget(this, CAControl_selector(MyTableViewCell::cellBtnCallback), CAControlEventTouchUpInSide); this->addSubview(cellBtn); }
void FirstViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. CCRect winRect = this->getView()->getBounds(); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("r/HelloWorld.png")); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageInside); imageView->setFrame(winRect); this->getView()->addSubview(imageView); CALabel* label = CALabel::createWithCenter(CCRect(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); }
void CANavigationBar::showTitle() { CCRect rect; rect.origin = this->getBounds().size/2; rect.size.height = this->getBounds().size.height; rect.size.width = this->getBounds().size.width - rect.size.height * 4; if (m_pTitle) { this->removeSubview(m_pTitle); m_pTitle = NULL; } CAImage* image = m_pItems.back()->getTitleViewImage(); if (image) { float height = MIN(image->getContentSize().height, rect.size.height * 0.75f); float width = height * image->getContentSize().width / image->getContentSize().height; width = MIN(rect.size.width, width); rect.size = CCSize(width, height); m_pTitle = CAImageView::createWithImage(image); m_pTitle->setCenter(rect); this->addSubview(m_pTitle); } else { int fontSize = this->getBounds().size.height * 0.35f / CROSSAPP_ADPTATION_RATIO; CALabel* title = CALabel::createWithCenter(rect); title->setTextAlignment(CATextAlignmentCenter); title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); title->setNumberOfLine(1); title->setColor(CAColor_white); title->setFontSize(fontSize); this->addSubview(title); m_pTitle = title; } if (!m_pItems.empty()) { std::string str = m_pItems.back()->getTitle(); ((CALabel*)m_pTitle)->setText(str.c_str()); } }