//
// TabBarViewController.h
// LittleLoveLive
//
// Created by Beryl
//
// TabBarViewController.m
// LittleLoveLive
//
// Created by Beryl on 16/7/16.
// Copyright ? 2016年 Beryl. All rights reserved.
//
#import "TabBarViewController.h"
#import "RootNavigationController.h"
#import "HomeViewController.h"
#import "LiveViewController.h"
#import "MeViewController.h"
@interface TabBarViewController ()
@end
@implementation TabBarViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupTheLine];
[self initialControllers];
}
//初始化子控制器
-(void)initialControllers {
[self setupController:[[HomeViewController alloc]init] image:@"icon_home_normal.png" selectedImage:@"icon_home_pressed.png" title:nil];
[self setupController:[[LiveViewController alloc]init] image:@"icon_live_normal.png" selectedImage:@"icon_live_pressed.png" title:nil];
[self setupController:[[MeViewController alloc] init] image:@"icon_me_normal.png" selectedImage:@"icon_me_pressed.png" title:nil];
}
//設(shè)置控制器
-(void)setupController:(UIViewController *)childVc image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
//標(biāo)題
childVc.title = title;
//childVc.view.backgroundColor = RGBACOLOR(239.0f, 239.0f, 244.0f, 1.0f);
//tabBarItem圖片
childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//tabBarItem字體的設(shè)置
//正常狀態(tài)
NSMutableDictionary *normalText = [NSMutableDictionary dictionary];
normalText[NSForegroundColorAttributeName] = [UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
[childVc.tabBarItem setTitleTextAttributes:normalText forState:UIControlStateNormal];
//選中狀態(tài)
NSMutableDictionary *selectedText = [NSMutableDictionary dictionary];
selectedText[NSForegroundColorAttributeName] = [UIColor blackColor];
[childVc.tabBarItem setTitleTextAttributes:selectedText forState:UIControlStateSelected];
RootNavigationController *nav = [[RootNavigationController alloc]initWithRootViewController:childVc];
[self addChildViewController:nav];
}
//設(shè)置分割線
-(void)setupTheLine {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -8, self.tabBar.frame.size.width, self.tabBar.frame.size.height)];
[imageView setImage:[UIImage imageNamed:@"bg_tabbar"]];
[imageView setContentMode:UIViewContentModeCenter];
[self.tabBar insertSubview:imageView atIndex:0];
//覆蓋原生Tabbar的上橫線
[[UITabBar appearance] setShadowImage:[self createImageWithColor:[UIColor clearColor]]];
[[UITabBar appearance] setBackgroundImage:[self createImageWithColor:[UIColor clearColor]]];
//設(shè)置TintColor
// UITabBar.appearance.tintColor = [UIColor orangeColor];
}
-(UIImage*) createImageWithColor:(UIColor*) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
//設(shè)置中間按鈕不受TintColor影響
- (void)awakeFromNib {
[super awakeFromNib];
NSArray *items = self.tabBar.items;
//設(shè)置第幾個 tabBar不受影響
UITabBarItem *btnAdd = items[1];
btnAdd.image = [btnAdd.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
btnAdd.selectedImage = [btnAdd.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
on 16/7/16.
// Copyright ? 2016年 YJ. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TabBarViewController : UITabBarController
@end
自定義弧形的 tabBar
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
推薦閱讀更多精彩內(nèi)容
- 自定義tabbar時,點擊自定義按鈕,不能正常顯示選中狀態(tài)時的圖片: 我剛開始在tabbar控制器中的viewDi...
- 自定義tabber,就是創(chuàng)建自己的tabbar蓋在系統(tǒng)的tabbar上面 //自定義tabbar GJWTabBa...
- 跳轉(zhuǎn)時添加隱藏 - (void)prepareForSegue:(UIStoryboardSegue *)segu...
- 1、自定義TabBar的效果圖 2、對于tabBar的自定義實現(xiàn)步驟 1、在tabBar中只可以布局5個tabBa...
- 幸福就是,清晨五點半,伴隨著小鳥的啾啾聲,你咦咦啊啊的張著小嘴,自說自話。然后轉(zhuǎn)頭,發(fā)現(xiàn)我在看你,瞬間,咧開沒牙的...