1

I have a TabBar Controller with two ViewControllers (A and B) and would like to change the font size of the two Tab Bar Items. When the first tab A ViewController is loaded, I can change the tab item font size using [self tabBarItem] setTitleTextAttribute.

However, how would I reference the tab bar item of the ViewController B from A so I can change the font as well?

Thanks in advance!

4

3 回答 3

2

您通过 self.tabbarController.viewControllers 引用了其他 viewController

于 2012-12-19T16:03:42.220 回答
0

您可以为 UITabBar 添加一个单例:共享实例并获取单个引用,或者您可以创建一个具有两个 UIViewController 及其随附的 UITabBar 的类,并将它们作为类变量调用。我不太喜欢单例,但它归结为您的应用程序的偏好和数据模型。

于 2012-12-19T16:05:10.477 回答
0

就像@andershqst 所说的那样self.tabbarController.viewControllers。我为我的标签维护一个枚举。

typedef enum SICOTabIndexes {
    kSICOTabIndexHome,
    kSICOTabIndexSaved,
    kSICOTabIndexCamera,
    kSICOTabIndexList,
    kSICOTabIndexSettings
} SICOTabIndexes;

然后我可以controller.tabBarController.viewControllers[kSICOTabIndexHome]用来获取特定的视图控制器。

UIViewController *homeController = controller.tabBarController.viewControllers[kSICOTabIndexHome]

此时,使用homeController.tabBarItem进行您需要的更改。

于 2012-12-19T16:10:22.233 回答