首先在appdelegate
导入
#import "WatchTabBarViewController.h"
#import "WatchTabBarItem.h"
然后设置根视图中 调用
- (void)customizeInterface {
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
UIImage *backgroundImage = nil;
NSDictionary *textAttributes = nil;
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
backgroundImage = [UIImage imageNamed:@"navigationbar_background_tall"];
textAttributes = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:18],
NSForegroundColorAttributeName: [UIColor blackColor],
};
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
backgroundImage = [UIImage imageNamed:@"navigationbar_background"];
textAttributes = @{
UITextAttributeFont: [UIFont boldSystemFontOfSize:18],
UITextAttributeTextColor: [UIColor blackColor],
UITextAttributeTextShadowColor: [UIColor clearColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
};
#endif
}
[navigationBarAppearance setBackgroundImage:backgroundImage
forBarMetrics:UIBarMetricsDefault];
[navigationBarAppearance setTitleTextAttributes:textAttributes];
}
在调用
- (void)setupViewControllers {
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *firstViewController = [storyBoard instantiateViewControllerWithIdentifier:@"homeController"];
UIViewController *firstNavigationController = [[UINavigationController alloc]
initWithRootViewController:firstViewController];
UIViewController *secondViewController = [[WatchFunCtionVC alloc] init];
UIViewController *secondNavigationController = [[UINavigationController alloc]
initWithRootViewController:secondViewController];
// UIViewController *thirdViewController = [storyBoard instantiateViewControllerWithIdentifier:@"homeController"];
MineController *thirdViewController = [[MineController alloc]init];
UIViewController *thirdNavigationController = [[UINavigationController alloc]
initWithRootViewController:thirdViewController];
WatchTabBarViewController *tabBarController = [[WatchTabBarViewController alloc] init];
[tabBarController setViewControllers:@[firstNavigationController,secondNavigationController,thirdNavigationController]];
self.viewController = tabBarController;
[self customizeTabBarForController:tabBarController];
}
指定显示的图片
- (void)customizeTabBarForController:(WatchTabBarViewController *)tabBarController {
// UIImage *finishedImage = [UIImage imageNamed:@""];
// UIImage *unfinishedImage = [UIImage imageNamed:@""];
// NSArray *tabBarItemImages = @[@"", @"", @""];
//
// NSInteger index = 0;
// for (WatchTabBarItem *item in [[tabBarController tabBar] items]) {
// [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
// UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",
// [tabBarItemImages objectAtIndex:index]]];
// UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",
// [tabBarItemImages objectAtIndex:index]]];
//
// [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
//
// index++;
// }
}
[[self rdv_tabBarController] setTabBarHidden:NO animated:YES];