美文网首页
创建TabBar

创建TabBar

作者: LGirl | 来源:发表于2016-07-15 18:18 被阅读16次
//继承TabBarController创建一个controller,并将这个controller设置为rootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupController];
}

//这个方法的意义就是改变系统默认的字体颜色值和字体大小
+(void)initialize{
    NSMutableDictionary *normalAttr = [NSMutableDictionary dictionary];
    normalAttr[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    normalAttr[NSForegroundColorAttributeName] = deSelectColor;
    
    NSMutableDictionary *selecAttr = [NSMutableDictionary dictionary];
    selecAttr[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    selecAttr[NSForegroundColorAttributeName] = ThemeColor;
    
    UITabBarItem *appearance = [UITabBarItem appearance];
    [appearance setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
    [appearance setTitleTextAttributes:selecAttr forState:UIControlStateSelected];
}

- (void)setupController{
    
    [self setupChildViewController:[[HomePageTableViewController alloc] initWithStyle:UITableViewStylePlain]
                             title:@"下厨房"
                             image:@"tabADeselected"
                       selectImage:@"tabASelected"];
    [self setupChildViewController:[[MarketViewController alloc] init]
                             title:@"市集"
                             image:@"tabBDeselected"
                       selectImage:@"tabBSelected"];
    [self setupChildViewController:[[CommuniteTableViewController alloc] initWithStyle:UITableViewStylePlain]
                             title:@"社区"
                             image:@"tabCDeselected"
                       selectImage:@"tabCSelected"];
    [self setupChildViewController:[[MineTableViewController alloc] initWithStyle:UITableViewStylePlain]
                             title:@"我的"
                             image:@"tabDDeselected"
                       selectImage:@"tabDSelected"];
    
}

- (void)setupChildViewController:(UIViewController *)controller title:(NSString *)Title image:(NSString *)Image selectImage:(NSString *)SelectImage{
    controller.tabBarItem.title = Title;
    controller.tabBarItem.image = [UIImage imageNamed:Image];
    controller.tabBarItem.selectedImage = [UIImage imageNamed:SelectImage];
    UINavigationController *NVC = [[UINavigationController alloc] initWithRootViewController:controller];
    [self addChildViewController:NVC];
}

相关文章

网友评论

      本文标题:创建TabBar

      本文链接:https://www.haomeiwen.com/subject/tiiyjttx.html