void CANavigationController::createWithContainer(CAViewController* viewController) { CAView* container = new CAView(); container->setFrame(this->getView()->getBounds()); this->getView()->addSubview(container); m_pContainers.pushBack(container); container->release(); CANavigationBar* navigationBar = CANavigationBar::create(DSize(this->getView()->getBounds().size.width, 0)); if (viewController->getNavigationBarItem() == NULL && viewController->getTitle().compare("") != 0) { viewController->setNavigationBarItem(CANavigationBarItem::create(viewController->getTitle())); } if (m_pViewControllers.empty()) { viewController->getNavigationBarItem()->setShowGoBackButton(false); } navigationBar->setItem(viewController->getNavigationBarItem()); if (m_pNavigationBarBackgroundImage) { navigationBar->setBackgroundView(CAScale9ImageView::createWithImage(m_pNavigationBarBackgroundImage)); } else { navigationBar->setBackgroundView(CAView::create()); } navigationBar->getBackgroundView()->setColor(m_sNavigationBarBackgroundColor); navigationBar->setTitleColor(m_sNavigationBarTitleColor); navigationBar->setTitleColor(m_sNavigationBarTitleColor); container->insertSubview(navigationBar, 1); navigationBar->setDelegate(this); m_pNavigationBars.pushBack(navigationBar); CAView* secondContainer = new CAView(); container->addSubview(secondContainer); secondContainer->release(); m_pSecondContainers.pushBack(secondContainer); viewController->m_pNavigationController = this; m_pViewControllers.pushBack(viewController); }
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(); }
void CATabBarController::viewDidLoad() { CCPoint tab_bar_rectOrgin = CCPointZero; CCRect container_rect = this->getView()->getBounds(); CCSize container_view_size = container_rect.size; container_view_size.width *= m_pViewControllers.size(); 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; } } m_pContainer = CAPageView::createWithFrame(container_rect, CAPageView::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_sTabBarSelectedBackGroundColor); } m_pTabBar->setTitleColorForNormal(m_sTabBarTitleColor); m_pTabBar->setTitleColorForSelected(m_sTabBarSelectedTitleColor); if (m_bShowTabBarSelectedIndicator) { m_pTabBar->showSelectedIndicator(); } m_pTabBar->setFrameOrigin(tab_bar_rectOrgin); this->getView()->addSubview(m_pTabBar); m_pTabBar->setSelectedAtIndex(m_nSelectedIndex); this->renderingSelectedViewController(); }