OGeek|极客世界-中国程序员成长平台

标题: ios - 是否可以从嵌入式 UITableViewController 设置父 UITabViewController 属性 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:03
标题: ios - 是否可以从嵌入式 UITableViewController 设置父 UITabViewController 属性

当谈到嵌入式 View 时,我有点困惑。我在 Storyboard 中创建了以下结构:

-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 并将代码放在那里。但是不必为此创建一个新类会很甜蜜。

一般问题,嵌入式 View 在此示例中如何工作?



Best Answer-推荐答案


我在我的一个项目中做到了这一点。试试这个:

[self.navigationController.tabBarItem setTitleTextAttributes{ NSForegroundColorAttributeName : [UIColor yellowColor] }
                                     forState:UIControlStateNormal];

[self.navigationController.tabBarItem setTitleTextAttributes{ NSForegroundColorAttributeName : [UIColor whiteColor] }
                                     forState:UIControlStateSelected];

如果它不适合你,请告诉我..

希望这会有所帮助!

关于ios - 是否可以从嵌入式 UITableViewController 设置父 UITabViewController 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35126154/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4