bool CATabBarController::initWithViewControllers(const std::vector<CAViewController*>& viewControllers) { CAViewController::init(); do { CC_BREAK_IF(viewControllers.size() == 0); m_pViewControllers.insert(m_pViewControllers.begin(), viewControllers.begin(), viewControllers.end()); std::vector<CATabBarItem*> items; for (unsigned int i=0; i<m_pViewControllers.size(); i++) { CAViewController* view = m_pViewControllers.at(i); view->retain(); view->m_pTabBarController = this; if (view->getTabBarItem() == NULL) { const char* title = CCString::createWithFormat("item%d",i)->getCString(); CATabBarItem* item = CATabBarItem::create(title, NULL, i); view->setTabBarItem(item); } items.push_back(view->getTabBarItem()); } m_pTabBar = CATabBar::create(items); m_pTabBar->retain(); m_pTabBar->setDelegate(this); } while (0); return true; }
bool CATabBarController::initWithViewControllers(const std::vector<CAViewController*>& viewControllers, CABarVerticalAlignment var) { CAViewController::init(); do { CC_BREAK_IF(viewControllers.size() == 0); m_pViewControllers.insert(m_pViewControllers.begin(), viewControllers.begin(), viewControllers.end()); std::vector<CATabBarItem*> items; for (unsigned int i=0; i<m_pViewControllers.size(); i++) { CAViewController* view = m_pViewControllers.at(i); view->retain(); view->m_pTabBarController = this; if (view->getTabBarItem() == NULL) { const char* title = CCString::createWithFormat("item%d",i)->getCString(); CATabBarItem* item = CATabBarItem::create(title, NULL); item->setTag(i); view->setTabBarItem(item); } items.push_back(view->getTabBarItem()); } m_pTabBar = CATabBar::create(items); m_pTabBar->retain(); m_pTabBar->setAnchorPoint(CCPointZero); m_pTabBar->setDelegate(this); m_pContainer = new CAScrollView(); m_pContainer->initWithFrame(CCRectZero); m_pContainer->setScrollEnabled(false); m_pContainer->setBounces(false); m_pContainer->setShowsHorizontalScrollIndicator(false); m_pContainer->setShowsVerticalScrollIndicator(false); } while (0); m_eTabBarVerticalAlignment = var; return true; }
bool CATabBarController::initWithViewControllers(const CAVector<CAViewController*>& viewControllers, CABarVerticalAlignment var) { CAViewController::init(); do { CC_BREAK_IF(viewControllers.size() == 0); m_pViewControllers = viewControllers; std::vector<CATabBarItem*> items; for (unsigned int i=0; i<m_pViewControllers.size(); i++) { CAViewController* view = m_pViewControllers.at(i); if (view->getTabBarItem() == NULL) { char title[8]; sprintf(title, "item%d", i); CATabBarItem* item = CATabBarItem::create(title, NULL); item->setTag(i); view->setTabBarItem(item); } items.push_back(view->getTabBarItem()); view->m_pTabBarController = this; } m_pTabBar = CATabBar::create(items); m_pTabBar->retain(); m_pTabBar->setDelegate(this); } while (0); m_eTabBarVerticalAlignment = var; return true; }
void CATabBarController::viewDidLoad() { std::vector<CATabBarItem*> items; for (unsigned int i=0; i<m_pViewControllers.size(); i++) { CAViewController* view = m_pViewControllers.at(i); if (view->getTabBarItem() == NULL) { char title[8]; sprintf(title, "item%d", i); CATabBarItem* item = CATabBarItem::create(title, NULL); item->setTag(i); view->setTabBarItem(item); } items.push_back(view->getTabBarItem()); view->m_pTabBarController = this; } m_pTabBar = CATabBar::create(items, DSize(this->getView()->getBounds().size.width, 0), m_eTabBarVerticalAlignment); this->getView()->addSubview(m_pTabBar); m_pTabBar->setDelegate(this); DRect container_rect = this->getView()->getBounds(); DPoint tab_bar_rectOrgin = DPointZero; if (m_bTabBarHidden) { tab_bar_rectOrgin = this->getTabBarTakeBackPoint(); } else { tab_bar_rectOrgin = this->getTabBarOpenPoint(); container_rect.size.height -= m_pTabBar->getFrame().size.height; if (m_eTabBarVerticalAlignment == CABarVerticalAlignmentTop) { container_rect.origin.y = m_pTabBar->getFrame().size.height; } } DSize container_view_size = container_rect.size; container_view_size.width *= m_pViewControllers.size(); m_pContainer = CAPageView::createWithFrame(container_rect, CAPageViewDirectionHorizontal); m_pContainer->setBackgroundColor(CAColor_clear); m_pContainer->setPageViewDelegate(this); m_pContainer->setScrollViewDelegate(this); m_pContainer->setScrollEnabled(m_bScrollEnabled); m_pContainer->setDisplayRange(true); this->getView()->addSubview(m_pContainer); CAVector<CAView*> views; for (int i=0; i<m_pViewControllers.size(); i++) { CAView* view = new CAView(); views.pushBack(view); view->release(); } m_pContainer->setViews(views); if (m_pTabBarBackgroundImage) { m_pTabBar->setBackgroundImage(m_pTabBarBackgroundImage); } else { m_pTabBar->setBackgroundColor(m_sTabBarBackgroundColor); } if (m_pTabBarSelectedBackgroundImage) { m_pTabBar->setSelectedBackgroundImage(m_pTabBarSelectedBackgroundImage); } else { m_pTabBar->setSelectedBackgroundColor(m_sTabBarSelectedBackgroundColor); } if (m_pTabBarSelectedIndicatorImage) { m_pTabBar->setSelectedIndicatorImage(m_pTabBarSelectedIndicatorImage); } else { m_pTabBar->setSelectedIndicatorColor(m_sTabBarSelectedIndicatorColor); } m_pTabBar->setTitleColorForNormal(m_sTabBarTitleColor); m_pTabBar->setTitleColorForSelected(m_sTabBarSelectedTitleColor); if (m_bShowTabBarSelectedIndicator) { m_pTabBar->showSelectedIndicator(); } m_pTabBar->setFrameOrigin(tab_bar_rectOrgin); m_pTabBar->setSelectedAtIndex(m_nSelectedIndex); this->renderingSelectedViewController(); }