- (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的封装
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 在首页push viewcontroller, 显示viewcontroler时tab bar 会在底部闪一下才消...
- 一般使用tabbar的时候,隐藏有两种方法. 一种是设置当前所处界面的隐藏属性 self.tabBarContro...