コード例 #1
0
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);
}
コード例 #2
0
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));
    }
}