iOS-TabBar的封装

- (void)setItemWithController:(UIViewController *)viewController title:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage
{
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
    [viewController.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateSelected];
    
    GJFNavigatuonController *nvc = [[GJFNavigatuonController alloc]initWithRootViewController:viewController];
    nvc.navigationBar.barTintColor = [UIColor orangeColor];
    [self addChildViewController:nvc];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    GJFCookBookController *cookBook = [[GJFCookBookController alloc]init];
    
    [self setItemWithController:cookBook title:@"食谱" image:@"tabbar_cookbook_normal.png" selectImage:@"tabbar_cookbook_hightlight"];
    
    GJFLikeViewController *like = [[GJFLikeViewController alloc]init];
    
    [self setItemWithController:like title:@"喜欢" image:@"tabbar_like_normal.png" selectImage:@"tabbar_like_hightlight"];
    
    GJFLessonViewController *lesson = [[GJFLessonViewController alloc]init];
    [self setItemWithController:lesson title:@"食客" image:@"tabbar_lesson_normal.png" selectImage:@"tabbar_lesson_hightlight"];
    
    GJFMineViewController *mine = [[GJFMineViewController alloc]init];
    
    [self setItemWithController:mine title:@"我的" image:@"tabbar_mine_normal.png" selectImage:@"tabbar_mine_hightlight"];
    
}

你可能感兴趣的:(iOS-TabBar的封装)