这是一个接近原生 UITabBarController 的 TabBar 控制器,支持 Lottie 动效,也可以在此基础上进行一些滑块切换动画
特性
- 支持 Lottie 动画。
- 支持 lottie 和 image 混合使用。
- 支持横竖屏切换及排版动态变化。
- 支持 XIB 创建
- 滑块切换动画
注意事项
-
当同时存在 lottie 和 image 时,如果导入 Lottie 仓库,则 Lottie 将隐藏 Image(lottie 为第一响应序列)
-
只有标题时将居中展示(image 为 nil)
-
只有 image 或者只有 lottie 都将居中展示(title 为 nil)
安装
Cocoapods
1. 在 Podfile 中添加 pod ‘JHTabBarController’
,要使用 Lottie 效果请添加 pod 'JHTabBarController/Lottie'
2. 执行 pod install 或 pod update
3. 导入 import JHTabBarController
Swift Package Manager
从 Xcode 11 开始,集成了 Swift Package Manager,使用起来非常方便。JHTabBarController 也支持通过 Swift Package Manager 集成。
在 Xcode 菜单栏中选择 File > Swift Packages > Add Pacakage Dependency
,然后在搜索栏输入
https://github.com/jackiehu/JHTabBarController
,即可完成集成,默认依赖 Lottie。
手动集成
JHTabBarController 也支持手动集成,只需将 Sources 文件夹中的 JHTabBarController 文件夹拖入要集成的项目中即可。
参数
var image 默认icon
var selectedImage 选中状态icon
var title 标题
var lottieName: Lottie文件名称
var textFontSize 标题字体大小
var textColor 标题未选中颜色
var selectedTextColor 标题选中颜色
var renderingMode: Bool icon是否使用图片自带颜色
var iconColor icon使用自定义颜色 默认颜色
var selectedIconColor icon使用自定义颜色 选中颜色
使用
纯代码创建:
let v1 = ViewController()
let item1 = UITabBarItem()
item1.image = UIImage.init(named: "tab_chat_nor")
item1.selectedImage = UIImage.init(named: "tab_chat_hi")
item1.title = "123"
v1.tabBarItem = item1
let v2 = ViewController()
let item2 = UITabBarItem()
item2.image = UIImage.init(named: "tab_home_nor")
item2.selectedImage = UIImage.init(named: "tab_home_hi")
v2.tabBarItem = item2
let v3 = ViewController()
let item3 = UITabBarItem()
item3.image = UIImage.init(named: "tab_mine_nor")
item3.selectedImage = UIImage.init(named: "tab_mine_hi")
item3.lottieName = "03"
v3.tabBarItem = item3
let nav1 = UINavigationController.init(rootViewController: v1)
let nav2 = UINavigationController.init(rootViewController: v2)
let nav3 = UINavigationController.init(rootViewController: v3)
let tab = JHTabBarController()
tab.viewControllers = [nav1,nav2,nav3]
tab.selectedIndex = 0
let windowScene = scene as! UIWindowScene
window? = UIWindow.init(windowScene: windowScene)
window?.frame = windowScene.coordinateSpace.bounds
window?.makeKeyAndVisible()
window?.rootViewController = tab
window?.backgroundColor = .white
Storyboard创建:
![]() |
![]() |
---|---|
![]() |
![]() |
具体用法请参见Demo。