项目中 -- 设置tabBar样式 (旅游局)

时间:2023-03-08 18:27:08
项目中 -- 设置tabBar样式 (旅游局)

- (void)addChildViewController:(UIViewController *)ViewController image:(UIImage *)image selectImg:(UIImage *)selectImg title:(NSString *)title navTitle:(NSString *)navTitle{

// 设置navigationBarItem 和 tabBarItem

ViewController.title = title;

// 关键代码 将系统的tabBar的title上调

[ViewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -3)];

ViewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

ViewController.tabBarItem.selectedImage = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

// 设置tabBarItem title样式

[ViewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor grayColor]} forState:UIControlStateNormal];

[ViewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];

// 添加导航栏

UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:ViewController];

ViewController.navigationItem.title = navTitle;

[self addChildViewController:navigation];

}