【发布时间】:2016-02-01 08:43:01
【问题描述】:
当谈到嵌入式视图时,我有点困惑。我在情节提要中创建了以下结构:
-UITabBarViewController
-UINavigationViewController
-UITableViewController (MyTableViewController)
所以对于我的问题,是否可以从我的自定义 UITableViewController (MyTableViewController) 中设置标签栏项目属性,例如标题字体?
我在 MyTableViewController 中尝试过以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Set tab bar item title
[self setTitle:@"TEST"]; // This works, it sets the title of the tab bar item
// This does not work
[self.tabBarController.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor yellowColor] }
forState:UIControlStateNormal];
[self.tabBarController.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateSelected];
// This does not work
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor yellowColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateSelected];
} // viewDidLoad
我知道我可以创建一个自定义 MyTabBarViewController 并将代码放在那里。但是不必为此创建一个新类会很甜蜜。
一般问题,嵌入式视图在此示例中如何工作?
【问题讨论】:
标签: ios objective-c storyboard