- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.delegate = self; /************************隐藏tabbar上的黑色线条***************************/ CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); CGContextFillRect(context, rect); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self.tabBar setBackgroundImage:img]; [self.tabBar setShadowImage:img]; /************************隐藏tabbar上的黑色线条***************************/ UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"首页" image:[[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0]; item1.selectedImage = [[UIImage imageNamed:@"tabbar_home_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"" image:[[UIImage imageNamed:@"tabbar_order"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0]; UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"我的" image:[[UIImage imageNamed:@"tabbar_person"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:0]; item3.selectedImage = [[UIImage imageNamed:@"tabbar_person_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; NSArray *controllers = @[@"HomePage",@"Order",@"Person"]; for (int i = 0; i < 3; i++) { Class cls = NSClassFromString([NSString stringWithFormat:@"%@ViewController",controllers[i]]); UIViewController *controller = (UIViewController *)[[cls alloc] init]; UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:controller]; nc.tabBarItem = @[item1,item2,item3][i]; [self addChildViewController:nc]; } UIImageView *tabbarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.tabBar.frame.size.height - 61, SCREEN_WIDTH, 61)]; tabbarView.image = [UIImage imageNamed:@"tabbar"]; [self.tabBar addSubview:tabbarView]; } - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { if (viewController == self.viewControllers[1]) { //点击中间tabbarItem,不切换,让当前页面跳转 OrderViewController *order = [[OrderViewController alloc] init]; order.hidesBottomBarWhenPushed = YES; [(UINavigationController *)tabBarController.selectedViewController pushViewController:order animated:YES]; return NO; } return YES; }
时间: 2024-10-11 07:43:16