void DMCatalogController::initWithCollectionView() { CADipRect rect = this->getView()->getBounds(); m_uiItems = (unsigned int)(rect.size.width / 300); m_uiItems = MIN(m_uiItems, 5); m_uiItems = MAX(m_uiItems, 3); m_pCollectionView = CACollectionView::createWithFrame(rect); m_pCollectionView->setCollectionViewDataSource(this); m_pCollectionView->setCollectionViewDelegate(this); m_pCollectionView->setScrollViewDelegate(this); CAPullToRefreshView* view = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader); m_pCollectionView->setHeaderRefreshView(view); m_pCollectionView->setBackGroundColor(CAColor_clear); this->getView()->addSubview(m_pCollectionView); m_pCollectionView->setAllowsSelection(true); m_pCollectionView->setHoriInterval(_px(30)); m_pCollectionView->setVertInterval(_px(10)); float width = this->getView()->getBounds().size.width; m_pCollectionView->setCollectionHeaderHeight(width * 15/32.0f); CAButton* bg = CAButton::createWithFrame(CADipRect(0, 0, rect.size.width, _dip(m_pCollectionView->getCollectionHeaderHeight())), CAButtonTypeCustom); m_pHeaderImageView = CommonUrlImageView::createWithImage(NULL); bg->setBackGroundViewForState(CAControlStateNormal, m_pHeaderImageView); bg->addTarget(this, CAControl_selector(DMCatalogController::onButton), CAControlEventTouchUpInSide); m_pCollectionView->setCollectionHeaderView(bg); CADipRect headerRect = CADipRectZero; headerRect.size = rect.size; headerRect.size.height = 76; headerRect.origin.y = _dip(m_pCollectionView->getCollectionHeaderHeight()) - 76; CAImageView* imageView = CAImageView::createWithFrame(headerRect); imageView->setImage(CAImage::create(title_bg_first)); bg->insertSubview(imageView,1); headerRect.origin.x = 25; headerRect.size.height -= 20; headerRect.size.width -= headerRect.origin.x; headerRect.origin.y = _dip(m_pCollectionView->getCollectionHeaderHeight()) - headerRect.size.height; m_pHeaderLabel = CALabel::createWithFrame(headerRect); m_pHeaderLabel->setFontSize(_px(28)); m_pHeaderLabel->setColor(CAColor_white); m_pHeaderLabel->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); bg->insertSubview(m_pHeaderLabel,1); if (!m_mvData[m_sTitle].empty()) { const DMBriefInfo& info = m_mvData[m_sTitle].front(); m_pHeaderLabel->setText("《" + info.title + "》" + info.subtitle); m_pHeaderImageView->setUrl(info.cover); } }
bool CATabBar::init(const CAVector<CATabBarItem*>& items, const CCSize& size) { if (!CAView::init()) { return false; } this->setColor(CAColor_clear); this->setItems(items); CCSize winSize = CAApplication::getApplication()->getWinSize(); CCSize contentSize = size.equals(CCSizeZero) ? CCSize(winSize.width, _px(98)) : size; this->setContentSize(contentSize); CADipRect rect = this->getBounds(); rect.origin = rect.size / 2; rect.size.width = MIN(rect.size.width, 1024); m_pContentView = new CAView(); m_pContentView->setCenter(rect); this->addSubview(m_pContentView); m_pContentView->release(); unsigned int count = (unsigned int)m_pItems.size(); m_cItemSize = m_pContentView->getBounds().size; m_cItemSize.width = rect.size.width/count; if (m_pButtons.empty()) { for (unsigned int i=0; i<count; i++) { CADipRect rect = CADipRectZero; rect.size = m_cItemSize; rect.origin.x = m_cItemSize.width * i; CAButton* btn = CAButton::createWithFrame(rect, CAButtonTypeCustom); m_pContentView->addSubview(btn); btn->setTag(i); btn->addTarget(this, CAControl_selector(CATabBar::setTouchSelected), CAControlEventTouchUpInSide); m_pButtons.pushBack(btn); CABadgeView* badgeView = new CABadgeView(); badgeView->init(); badgeView->setCenter(CADipRect(rect.size.width, 25, 0, 0)); btn->insertSubview(badgeView, 10); m_pBadgeViews.pushBack(badgeView); } } if (m_pBackGroundImage == NULL) { this->setBackGroundImage(CAImage::create("source_material/tabBar_bg.png")); } if (m_pSelectedBackGroundImage == NULL) { this->setSelectedBackGroundImage(CAImage::create("source_material/tabBar_selected_bg.png")); } if (m_pSelectedIndicatorImage == NULL) { this->setSelectedIndicatorImage(CAImage::create("source_material/tabBar_selected_indicator.png")); } return true; }