void DMChartsController::onSegmented(CAControl* control, CCPoint point) { CASegmentedControl* segmentedControl = (CASegmentedControl*)control; int index = segmentedControl->getSelectedIndex(); switch (index) { case 0: current_Set = all_Set; break; case 1: current_Set = month_Set; break; case 2: current_Set = week_Set; break; } for (int i = 0 ; i<m_pCurrTableViews.size(); i++) { if (i==index) { m_pCurrTableViews.at(i)->setVisible(true); m_pCurrTableViews.at(i)->reloadData(); } else { m_pCurrTableViews.at(i)->setVisible(false); } } // m_pTableView->reloadData(); }
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); }
CASegmentedControl* CASegmentedControl::createWithCenter(const CCRect& rect, unsigned int itemsCount) { CASegmentedControl* segmentedControl = new CASegmentedControl(itemsCount); if (segmentedControl && segmentedControl->initWithCenter(rect)) { segmentedControl->autorelease(); return segmentedControl; } CC_SAFE_DELETE(segmentedControl); return NULL; }
void FirstViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. CCSize size = this->getView()->getBounds().size; label = CALabel::createWithCenter(CCRect(size.width/2, 60, 200, 50)); label->setTextAlignment(CATextAlignmentCenter); label->setFontSize(size.width/20); label->setText("0.000000"); this->getView()->addSubview(label); float height = size.width * 0.8f * 0.15f; float off_Y = size.width * 0.8f * 0.15f + 10; CCRect progress_rect = CCRect(size.width / 2, off_Y + 60, size.width * 0.8f, 10); progress = CAProgress::create(); progress->setCenter(progress_rect); this->getView()->addSubview(progress); CCRect slider_rect = CCRect(size.width/2, off_Y * 2 + 60, size.width * 0.8f, height); CASlider* slider = CASlider::createWithCenter(slider_rect); this->getView()->addSubview(slider); slider->addTarget(this, CAControl_selector(FirstViewController::updateSlider)); CCRect segmentedControl_rect = CCRect(size.width/2, off_Y * 3 + 60, size.width * 0.8f, height); CASegmentedControl* segmentedControl = CASegmentedControl::createWithCenter(segmentedControl_rect, 2); segmentedControl->insertSegmentWithTitle("2", 2, CAControlStateAll); segmentedControl->insertSegmentWithTitle("3", 3, CAControlStateAll); this->getView()->addSubview(segmentedControl); CAButton* btn = CAButton::createWithCenter(CCRect(size.width/2, size.height - off_Y, 150, 60), CAButtonTypeRoundedRect); btn->setTitleForState(CAControlStateAll, "OK"); this->getView()->addSubview(btn); btn->addTarget(this, CAControl_selector(FirstViewController::diss), CAControlEventTouchUpInSide); }
void DMChartsController::viewDidLoad() { CCRect rect = this->getView()->getBounds(); rect.size.height = _px(96); CAView* navigaView = CAView::createWithFrame(rect, ccc4(87, 154, 244, 255)); this->getView()->addSubview(navigaView); 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); navigaView->addSubview(button); button->addTarget(this, CAControl_selector(DMChartsController::onReturn), CAControlEventTouchUpInSide); CASegmentedControl *segmentedControl = CASegmentedControl::createWithFrame(CCRect(0, 0, 10, 10), 3); segmentedControl->setTitleAtIndex("总", 0, CAControlStateAll); segmentedControl->setTitleAtIndex("月", 1, CAControlStateAll); segmentedControl->setTitleAtIndex("周", 2, CAControlStateAll); for (int i=0; i<3; i++) { segmentedControl->setTitleColorAtIndex(ccc4(87, 154, 244, 255), i, CAControlStateSelected); segmentedControl->setTitleColorAtIndex(CAColor_white, i, CAControlStateHighlighted); segmentedControl->setTitleColorAtIndex(CAColor_white, i, CAControlStateNormal); } segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal1), 0, CAControlStateNormal); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal1), 0, CAControlStateHighlighted); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected1), 0, CAControlStateSelected); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal3), 1, CAControlStateNormal); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal3), 1, CAControlStateHighlighted); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected3), 1, CAControlStateSelected); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal2), 2, CAControlStateNormal); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segNormal2), 2, CAControlStateHighlighted); segmentedControl->setBackgroundImageAtIndex(CAImage::create(segSelected2), 2, CAControlStateSelected); segmentedControl->addTarget(this, CAControl_selector(DMChartsController::onSegmented)); segmentedControl->setSelectedAtIndex(0); float segmentwid = 300; CCRect segR = CCRect((this->getView()->getFrame().size.width-_px(segmentwid))/2, _px(15), _px(segmentwid), _px(62)); segmentedControl->setFrame(segR); navigaView->addSubview(segmentedControl); this->searchTopItems(); { 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.3f); m_pLoading->setColor(CAColor_white); this->getView()->insertSubview(m_pLoading, CAWindowZoderTop); m_pLoading->setTargetOnCancel(this, callfunc_selector(DMChartsController::initWithTableView)); } }