CATabBarController(標(biāo)簽欄控制器)

2018-09-08 16:43 更新

類說明

視圖管理器的派生類,CATabBarController作為一個特殊的視圖管理器,負(fù)責(zé)協(xié)調(diào)多個視圖管理器之間的工作,是對視圖管理器的一種特殊封裝。通常當(dāng)你的程序需要使用一些平行的界面,這里說的平行界面就是程序中的某些功能界面是處于平級的,這些功能界面可以相互切換,tabBarController就很適合這種情況。


基類

CAViewController,CATabBarDelegate,CAPageViewDelegate,CAScrollViewDelegate


CATabBarController 屬性點擊查看方法介紹)

屬性說明
ScrollEnabledTabBar可以滑動切換
TabBarHidden查看TabBar是否隱藏
TabBarVerticalAlignmentTabBar對齊方式
TabBarBackGroundImageTabBar的背景圖像
TabBarBackGroundColorTabBar的背景顏色
TabBarSelectedBackGroundImageTabBar選擇狀態(tài)下背景的圖像
TabBarSelectedBackGroundColorTabBar選擇狀態(tài)下背景的顏色
TabBarSelectedIndicatorImageTabBar選擇狀態(tài)下的指標(biāo)圖像
TabBarSelectedIndicatorColorTabBar選擇狀態(tài)下的指標(biāo)顏色
TabBarTitleColorForNormalTabBar標(biāo)題為正常狀態(tài)的顏色
TabBarTitleColorForSelectedTabBar標(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的索引值
setTabBarHiddenTabBar顯示或隱藏
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(falsefalse);
     
    //默認(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 屬性

ScrollEnabled

類型:bool

解釋:TabBar可以滑動切換。is/set{}。

    

TabBarHidden

類型:bool

解釋:查看TabBar是否隱藏。is{}。


TabBarVerticalAlignment

類型:CABarVerticalAlignment

解釋:TabBar對齊方式。get{}。


TabBarBackGroundImage

類型:CAImage*

解釋:TabBar的背景圖像。set/get{}。


TabBarBackGroundColor

類型:CAColor4B

解釋:TabBar的背景顏色。set/get{}。


TabBarSelectedBackGroundImage

類型:CAImage*

解釋:TabBar選擇狀態(tài)下背景的圖像。set/get{}。


TabBarSelectedBackGroundColor

類型:CAColor4B

解釋:TabBar選擇狀態(tài)下背景的顏色set/get{}。


TabBarSelectedIndicatorImage

類型:CAImage*

解釋:TabBar選擇狀態(tài)下指標(biāo)的圖像。set/get{}。


TabBarSelectedIndicatorColor

類型:CAColor4B

解釋:TabBar選擇狀態(tài)下指標(biāo)的顏色set/get{}。


TabBarTitleColorForNormal

類型:CAColor4B

解釋:TabBar標(biāo)題為正常的顏色。set/get{}。


TabBarTitleColorForSelected

類型: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ù)組
CABarVerticalAlignmentvar = 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 intindex索引位置(從0開始)

解釋:獲取當(dāng)前顯示view的viewController的索引值


CAViewController* getSelectedViewController();

返回值:CAViewController*

參數(shù):

解釋:獲取當(dāng)前選中的viewController


virtual bool showSelectedViewControllerAtIndex(unsigned int index);

返回值:bool

參數(shù):

類型參數(shù)名說明
unsigned intindex索引位置(從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ù)名說明
boolhidden是否隱藏(默認(rèn)false)
boolanimated是否開啟動畫效果

解釋:TabBar的顯示與隱藏


void updateItem(CAViewController* viewController);

返回值:void

參數(shù):

類型參數(shù)名說明
CAViewController*viewController需要更新的視圖管理器

解釋:更新視圖


void showTabBarSelectedIndicator();

返回值:void

參數(shù):

解釋:顯示刷新TabBar

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號