初始一个程序(UITabBarController为根视图)

1.UITabBarController的写法

- (void)tab{
UITabBarController *  tbc = [[UITabBarController alloc]init];
vc1 *v1 = [vc1 new];
v1.title = @"首页";
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:v1];
UIImage *img1 = [UIImage imageNamed:@"tab1"];
v1.tabBarItem.image = img1;
vc2 *v2 = [vc2 new];
v2.title = @"附近";
vc3 *v3 = [vc3 new];
v3.title = @"搜索";
v3.tabBarItem.badgeValue = @"3";
vc4 *v4 = [vc4 new];
v4.title = @"设置";
NSArray *arr = @[nc,v2,v3,v4];
tbc.viewControllers = arr;
tbc.selectedIndex = 0;
[tbc.tabBar setTintColor:[UIColor greenColor]];
[tbc.tabBar setBarTintColor:[UIColor orangeColor]];
self.window.rootViewController = tbc;
}

2.StoryboardCode 起始程序TabBarController

UIStoryboard * mainstoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabbar = [mainstoryBoard instantiateInitialViewController];
//首页故事板
    UIStoryboard * faceStoryboard = [UIStoryboard storyboardWithName:@"Face" bundle:nil];
    UINavigationController * faceNaVC = [faceStoryboard instantiateInitialViewController];
    [faceNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"titleBar"] forBarMetrics:UIBarMetricsDefault];
    faceNaVC.tabBarItem.image = [[UIImage imageNamed:@"dingdan_hui"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    faceNaVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"dingdan_lan"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [faceNaVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGBA(168, 168, 168, 1.0)} forState:UIControlStateNormal];
    [faceNaVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGBA(0, 170, 239, 1.0)} forState:UIControlStateHighlighted];
FaceViewController  * faceVC = [faceStoryboard instantiateViewControllerWithIdentifier:@"FaceViewController"];

3.页面都是故事版
想要改变tabbar的图片和文字

//tabbar颜色
    [[UITabBar appearance] setBarTintColor:[UIColor redColor]];
//去除图片原有蓝色层
    for (UITabBarItem *item in self.tabController.toolbarItems) {
        item.selectedImage = [item.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
    }
// 自定义文字颜色
     [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
     [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,263评论 4 61
  • 满江红—贺崤函雅集 ——荞麦皮 水墨丹青,香犹在,琴声溪若。 弦飞舞,未听先醉,古筝横卧。 一曲梵音禅心...
    荞麦皮1阅读 3,318评论 1 1
  • 1.请不要假装对我好,我很傻,会当真的。 2.谁把谁真的当真,谁为谁心疼。 3.爱那么短,遗忘那么长。 4.我还在...
    16aa5fab5f62阅读 1,716评论 0 0
  • 静思3D(四胆2) (内部研究)………个 301期1469开391对2 302期2479开241对2 303期24...
    静思梦彩阅读 1,072评论 0 1
  • 篾匠:用竹子剖成的薄片或丝编制用品的手艺人 随着朔料制品的出现,篾制品几乎被淘汰了。所以,可能现在很多人都没有用过...
    依米在312阅读 5,909评论 53 45