为什么要使用?
在开发工作中,我们可能会遇到需要自定义UITabBar的情况。例如:改变文字样式、添加一些动画效果、设置一个比默认更大的样式等等,以上需求如果只通过UITabBarItem往往很难实现。
有了ESTabBarController,你可以轻松地实现这些!
- | 功能 | 说明 |
---|
1 | 支持默认样式 | 如果直接使用ESTabBarController进行初始化,你会得到与UITabBarController完全相同的仿系统样式 UITabBarController样式: ESTabBarController仿系统样式: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/CustomStyle.png) |
2 | 支持带有"More"的默认样式 | 使用ESTabBarController进行初始化,若item大于最大显示数量则显示"More",样式与UITabBarController一致 带有"More"的UITabBarController样式: 带有"More"的ESTabBarController样式: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/CustomMoreStyle.png) |
3 | 支持UITabBarItem和ESTabBarItem混合 | 可以任意设置tabbar的items,支持即包含UITabBarItem,同时也包含ESTabBarItem ESTabBar和UITabBar混合样式: 带有'More'的ESTabBar和UITabBar混合样式: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/MixtureMoreStyle.png) |
4 | 支持UIKit属性 | 支持UITabBarController、UITabBar和UITabBarItem的大部分API属性,使原有代码无需任何修改即可无缝迁移到ESTabBarController 支持UITabBarController的selectedIndex 属性的实现: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/SelectIndexCode.png) |
5 | 支持与UINavigationController任意嵌套 | 通常在使用UITabBarController 过程中,会存在两种比较常见的层级处理方式: 第一种: ├── UITabBarController └──── UINavigationController └────── UIViewController └──────── SubviewControllers 第二种: ├── UINavigationController └──── UITabBarController └────── UIViewController └──────── SubviewControllers 第一种情况在push子视图的时候需要设置 hidesBottomBarWhenPushed = true , 第二种则不需要。 在ESTabBarController中,通过添加Container视图到UITabBar的方式来兼容这两种层级处理方式。 |
6 | 支持自定义 | 使用ESTabBarController可以实现: 1. 自定义选中颜色和样式 2. 添加选中时的动画效果 3. 自定义Item的背景颜色 4. 添加高亮时的动画效果 5. 添加一些动画暗示用户点击 6. 等等...... |
7 | 支持自定义按钮大小 支持自定义点击事件 | ESTabBarController支持自定义按钮的大小,你可以轻松定制不规则大小的tab按钮。 当按钮frame大于TabBar时,通过HitTest方法使其超出TabBar区域点击仍然有效。 另外,ESTabBarController能够自定义点击事件,并通过一个block回调给上层处理。 中间带有较大按钮样式: 带有特殊提醒框样式: 自定义按钮点击事件: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/CustomHitGif.gif) |
8 | 支持默认通知样式 | 如果直接使用ESTabBarController进行初始化,你会得到与UITabBarController完全相同的仿系统通知样式 UITabBarController样式: ESTabBarController仿系统样式: ![enter image description here](https://github.com/eggswift/ESTabBarController/raw/master/Resources/CustomNotificationStyle.png) |
9 | 支持自定义通知样式 | 使用ESTabBarController可以实现: 1. 自定义提醒动画 2. 自定义提醒样式 3. 等等...... |
10 | 支持Lottie | 通过自定义ContentView,能够添加Lottie的LAAnimationView到Item ![enter image description here](https://i-blog.csdnimg.cn/blog_migrate/fd72ef267d1d792bc8412b9a44dd2293.gif) |
支持环境
- Xcode 8 or later
- iOS 8.0 or later
- ARC
- Swift 3 or later
Demo
下载后运行ESTabBarControllerExample工程,你可以看到一些使用ESTabBarController实现的自定义TabBar的更多例子。
如何安装
CocoaPods
pod "ESTabBarController-swift"
Carthage
github "eggswift/ESTabBarController"
手动安装
git clone https://github.com/eggswift/ESTabBarController.git
open ESTabBarController
未完成的事
- Containers的布局方式目前是纯代码布局,使用Autolayout应该会更好。
- 当存在"More"时,若进行Edit会出现问题。
- UITabBarItem的部分属性还没有桥接到ESTabBarItem。
- ESTabBarItemMoreContentView中的"More"图片目前还未设置到framework中,计划将它转化为创建CGBitmap的代码。
感谢:
关于
ESTabBarController是由lihao开发和维护。如果你在使用过程中遇到什么疑问或任何问题,欢迎提交 issue 随时交流。
如果你想为ESTabBarController输出代码,请提交 Pull Request,我会尽可能快的去处理。