一个感天动地的高度自定义的 tabBarController!
你几乎可以自定义 100% 的属性!😍 ✨
In me the tiger sniffs the rose.
心有猛虎,细嗅蔷薇。
欢迎访问 我的博客:http://LeoDev.me
-
高度解耦!
所有控件全部作为一个单独的类拆开,项目耦合性超低!
-->
表示属于:LCTabBarBadge --> LCTabBarItem --> LCTabBar --> LCTabBarController
-
集成简单!
一步集成:把你
AppDelegate.m
中的UITabBarController
单词替换成LCTabBarController
即可完成集成!所以,就算你项目已经完成了,你依然可以随时集成!当然你也可以随时更换回
UITabBarController
!(但我有 200% 的把握你不会这么做!) -
零污染!
拥有
UITabBarController
的全部功能,而没有任何入侵行为!你要做的永远只有一步!LCTabBarController
利用 KVO 监听系统 tabBarItem,你任何对 tabBarItem 的设置都可以继续生效!如:viewController.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"]; // 生效!
someVC.hidesBottomBarWhenPushed = YES; // 生效!
-
高度自定义!
你可以自由设置下列属性,也可以选择去代码中直接改!
-
tabBar 标题字体颜色(普通、高亮等)
-
tabBar 标题字体
-
tabBar 图片所占比例
-
tabBar 小红点 frame
-
tabBar 小红点 字体
-
...
-
-
如果觉得还不错,请点击右上角 star!⭐️ 谢谢!
我会根据 Issue 持续更新,如果你想随时了解我的进度,请点击右上角的 watch!
把下面的代码添加到你的 Podfile 中:
pod 'LCTabBarController' # Podfile
直接把 LCTabBarController
文件夹拽入你的项目中,这个文件夹可以在 Demo 中找到。
-
在你的
AppDelegate.m
里面:// 0. 导入头文件 #import "LCTabBarController.h" // 1. 如果你项目已经开工,哪怕已经写完了 // 只需在 application:didFinishLaunchingWithOptions: 方法里面替换一句代码 UITabBarController *tabBarC = [[UITabBarController alloc] init]; -> LCTabBarController *tabBarC = [[LCTabBarController alloc] init]; // 2. 如果你刚刚开始写一个新项目 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; [self.window makeKeyAndVisible]; // 示例代码 HomeVC *vc1 = [[HomeVC alloc] init]; vc1.view.backgroundColor = [UIColor whiteColor]; vc1.tabBarItem.badgeValue = @"23"; vc1.title = @"Home"; vc1.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"]; vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_home_selected"]; // vc2 vc3 ... UIViewController *vc4 = [[UIViewController alloc] init]; vc4.view.backgroundColor = [UIColor yellowColor]; vc4.tabBarItem.badgeValue = @"99+"; vc4.title = @"Profile"; vc4.tabBarItem.image = [UIImage imageNamed:@"tabbar_profile"]; vc4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_profile_selected"]; UINavigationController *navC1 = [[UINavigationController alloc] initWithRootViewController:vc1]; UINavigationController *navC2 = [[UINavigationController alloc] initWithRootViewController:vc2]; UINavigationController *navC3 = [[UINavigationController alloc] initWithRootViewController:vc3]; UINavigationController *navC4 = [[UINavigationController alloc] initWithRootViewController:vc4]; /**************************************** Key Code ****************************************/ LCTabBarController *tabBarC = [[LCTabBarController alloc] init]; tabBarC.viewControllers = @[navC1, navC2, navC3, navC4]; self.window.rootViewController = tabBarC; /******************************************************************************************/ return YES; }
-
搞定!
-
你可以在通过更改
LCTabBarController
对象随意更改下列属性,其他更多属性可直接阅读代码更改!/**************************************** Key Code ****************************************/ LCTabBarController *tabBarC = [[LCTabBarController alloc] init]; // look here, you should set this properties before `- setViewControllers:` tabBarC.itemTitleFont = [UIFont boldSystemFontOfSize:11.0f]; tabBarC.itemTitleColor = [UIColor greenColor]; tabBarC.selectedItemTitleColor = [UIColor redColor]; tabBarC.itemImageRatio = 0.5f; tabBarC.badgeTitleFont = [UIFont boldSystemFontOfSize:12.0f]; tabBarC.viewControllers = @[navC1, navC2, navC3, navC4]; self.window.rootViewController = tabBarC; /******************************************************************************************/
然后你就可以看到类似下图的效果:
- #15 相关,公开
lcTabBar
属性。
- 修复 #13,Merged sunnysuhappy's pull #14。
- 更新 CocoaPods 来源。
-
修复使用 Swift + CocoaPods 时 bundle 找不到的问题。
-
支持 building。
-
修复 Bug:
当调用
popToRootViewController
方法后,系统 tabBar 原有的控件又重新显示出来了。 你可以在调用popToRootViewController
方法后,调用removeOriginControls
方法解决这个问题,像这样:[self.navigationController popToRootViewControllerAnimated:YES]; [lcTabBarController removeOriginControls];
- 改善自定义属性的方法,体验更佳!
tabBarItem
中的imageView
的contentModel
修改为UIViewContentModeCenter
。
- 修正
tabBarBadge
的x
。
- 公众版本。
-
适配 揽梦云签。
-
V 1.1.x 将为揽梦科技专用。
- 适配 揽梦云签。
tabBarItem
中的imageView
的contentModel
修改为UIViewContentModeScaleAspectFit
。
-
删除一些日志打印。
-
更新 demo 图片。
- UI 调整。
- Bug 修复。
-
初始化提交。
-
添加 CocoaPods 支持。
-
有问题请直接新建 Issue :)
-
Mail:
echo bGVvZGF4aWFAZ21haWwuY29tCg== | base64 -D
-
Blog: https://LeoDev.me
-
捐赠:
注:捐赠并不能会解锁额外的功能。
LCTabBarController is released under the MIT License.