類說明
視圖管理器的派生類,CATabBarController作為一個特殊的視圖管理器,負(fù)責(zé)協(xié)調(diào)多個視圖管理器之間的工作,是對視圖管理器的一種特殊封裝。通常當(dāng)你的程序需要使用一些平行的界面,這里說的平行界面就是程序中的某些功能界面是處于平級的,這些功能界面可以相互切換,tabBarController就很適合這種情況。
基類
CAViewController,CATabBarDelegate,CAPageViewDelegate,CAScrollViewDelegate
CATabBarController 屬性(點擊查看方法介紹)
屬性 | 說明 |
ScrollEnabled | TabBar可以滑動切換 |
TabBarHidden | 查看TabBar是否隱藏 |
TabBarVerticalAlignment | TabBar對齊方式 |
TabBarBackGroundImage | TabBar的背景圖像 |
TabBarBackGroundColor | TabBar的背景顏色 |
TabBarSelectedBackGroundImage | TabBar選擇狀態(tài)下背景的圖像 |
TabBarSelectedBackGroundColor | TabBar選擇狀態(tài)下背景的顏色 |
TabBarSelectedIndicatorImage | TabBar選擇狀態(tài)下的指標(biāo)圖像 |
TabBarSelectedIndicatorColor | TabBar選擇狀態(tài)下的指標(biāo)顏色 |
TabBarTitleColorForNormal | TabBar標(biāo)題為正常狀態(tài)的顏色 |
TabBarTitleColorForSelected | TabBar標(biāo)題為選定狀態(tài)的顏色 |
CATabBarController 方法(點擊查看方法介紹)
方法 | 說明 |
initWithViewControllers | 初始化CATabBar |
showSelectedViewController | 設(shè)置當(dāng)前被選中的viewController |
getViewControllerAtIndex | 獲取當(dāng)前顯示view的viewController的索引值 |
getSelectedViewController | 獲取當(dāng)前選中的viewController |
showSelectedViewControllerAtIndex | 根據(jù)索引值顯示當(dāng)前選中的viewController |
getSelectedViewControllerAtIndex | 獲取當(dāng)前的被選中的viewController的索引值 |
setTabBarHidden | TabBar顯示或隱藏 |
updateItem | 更新視圖 |
showTabBarSelectedIndicator | 顯示刷新TabBar |
創(chuàng)建與初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | FirstViewController* first= new FirstViewController(); first->init(); first->setTabBarItem(CATabBarItem::create(UTF8( "第一項" ),CAImage::create( "" ),CAImage::create( "" ))); SecondViewController* Second = new SecondViewController(); Second->init(); Second->setTabBarItem(CATabBarItem::create(UTF8( "第二項" ), CAImage::create( "" ), CAImage::create( "" ))); ThirdViewController* Third = new ThirdViewController(); Third->init(); Third->setTabBarItem(CATabBarItem::create(UTF8( "第三項" ), CAImage::create( "" ), CAImage::create( "" ))); //將多個ViewController放到CAVector進行管理 CAVector<CAViewController*> vector; vector.pushBack(first); vector.pushBack(Second); vector.pushBack(Third); //創(chuàng)建TabBar CATabBarController* tab = new CATabBarController(); //通過含有ViewControler的CAVector進行初始化 tab->initWithViewControllers(vector); //設(shè)置可以滑動切換 tab->setScrollEnabled( true ); tab->showTabBarSelectedIndicator(); this ->setRootViewController(tab); //是否內(nèi)存 first->release(); Second->release(); Third->release(); tab->release(); |
樣式
可設(shè)置樣式:文本、位置(上、下)、背景顏色、圖片
CATabBarItem控制:文本、默認(rèn)圖片、選中圖片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //title:文本,image:默認(rèn)背景圖片,selectedImage:選中時背景圖片 static CATabBarItem* create( const std::string& title, CAImage* image, CAImage* selectedImage = NULL); CATabBarController控制:顯示位置(初始時設(shè)置)、背景顏色、圖片 //初始時設(shè)置顯示位置在頂部 tab->initWithViewControllers(vector,CABarVerticalAlignmentTop); //是否隱藏TabBar tab->setTabBarHidden( false , false ); //默認(rèn)背景顏色 tab->setTabBarBackGroundColor(CAColor_orange); //默認(rèn)背景圖片 tab->setTabBarBackGroundImage(CAImage::create( "source_material/btn_left_blue.png" )); |
管理
主要是切換:
1 2 3 4 5 6 7 8 9 10 11 | /* *設(shè)置當(dāng)前被選中的viewController *viewController:要設(shè)置選中的指針 */ bool showSelectedViewController(CAViewController* viewController); /* *獲取當(dāng)前顯示view的viewController的索引值 *index:索引位置(從0開始) */ CAViewController* getViewControllerAtIndex(unsigned int index); |
CATabBarController 屬性
類型:bool
解釋:TabBar可以滑動切換。is/set{}。
類型:bool
解釋:查看TabBar是否隱藏。is{}。
類型:CABarVerticalAlignment
解釋:TabBar對齊方式。get{}。
類型:CAImage*
解釋:TabBar的背景圖像。set/get{}。
類型:CAColor4B
解釋:TabBar的背景顏色。set/get{}。
類型:CAImage*
解釋:TabBar選擇狀態(tài)下背景的圖像。set/get{}。
類型:CAColor4B
解釋:TabBar選擇狀態(tài)下背景的顏色。set/get{}。
類型:CAImage*
解釋:TabBar選擇狀態(tài)下指標(biāo)的圖像。set/get{}。
類型:CAColor4B
解釋:TabBar選擇狀態(tài)下指標(biāo)的顏色。set/get{}。
類型:CAColor4B
解釋:TabBar標(biāo)題為正常的顏色。set/get{}。
類型:CAColor4B
解釋:TabBar標(biāo)題為選定的顏色。set/get{}。
CATabBarController 方法
virtual bool initWithViewControllers(const CAVector<CAViewController*>& viewControllers,CABarVerticalAlignment var = CABarVerticalAlignmentBottom);
返回值:bool
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAVector<CAViewController*>& | viewControllers | 含有CAViewController的數(shù)組 |
CABarVerticalAlignment | var = CABarVerticalAlignmentBottom | 切換條位置(上部,下部) |
解釋:初始化CATabBar
bool showSelectedViewController(CAViewController* viewController);
返回值:bool
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 要設(shè)置選中的指針 |
解釋:設(shè)置當(dāng)前被選中的viewController
CAViewController* getViewControllerAtIndex(unsigned int index);
返回值:CAViewController*
參數(shù):
類型 | 參數(shù)名 | 說明 |
unsigned int | index | 索引位置(從0開始) |
解釋:獲取當(dāng)前顯示view的viewController的索引值
CAViewController* getSelectedViewController();
返回值:CAViewController*
參數(shù):
解釋:獲取當(dāng)前選中的viewController
virtual bool showSelectedViewControllerAtIndex(unsigned int index);
返回值:bool
參數(shù):
類型 | 參數(shù)名 | 說明 |
unsigned int | index | 索引位置(從0開始) |
解釋:根據(jù)索引值顯示當(dāng)前選中的viewController
virtual unsigned int getSelectedViewControllerAtIndex();
返回值:unsigned int
參數(shù):
解釋:獲取當(dāng)前的被選中的viewController的索引值
virtual void setTabBarHidden(bool hidden, bool animated);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
bool | hidden | 是否隱藏(默認(rèn)false) |
bool | animated | 是否開啟動畫效果 |
解釋:TabBar的顯示與隱藏
void updateItem(CAViewController* viewController);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 需要更新的視圖管理器 |
解釋:更新視圖
void showTabBarSelectedIndicator();
返回值:void
參數(shù):
解釋:顯示刷新TabBar
更多建議: