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

}