轻量级的自定义标签栏视图。
屏幕截图
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
功能
- 易于配置和设置。创建带有标题、图像或两者的标签页。
- 动态标签页配置。
- 在完成块中检测点击。
- 在单个标签页中显示/隐藏徽章值。轻松配置以满足需求。
- 锁定/解锁特定标签页。
- 轻松显示/隐藏 UINavigationBar 和 HHTabBarView。
- 轻量级,无依赖。
- 根据需求更改 HHTabBarView 的 UI(从左到右或从右到左)。
- 根据 UI 需求更改 HHTabBarView 位置。支持:顶部和底部(默认)。
注意:不建议在顶部显示 HHTabBarView。它始终在底部显示得最好。
安装
-
手动 – 将
HHTabBarView/Source
文件夹添加到您的项目中。然后您就可以使用HHTabBarView
了。 -
CocoaPods:–
pod 'HHTabBarView'
您可以阅读特定版本的 变更日志 文件。
配置
重要:请注意,HHTabBarView
目前不支持 UIStoryBoard
。这意味着您必须以编程方式创建 HHTabBarView
。建议在 AppDelegate.swift
中配置 HHTabBarView
以便于您使用。
- 初始化并保持对
HHTabBarView
的引用。📌
let hhTabBarView = HHTabBarView.shared
- 保持对 iOS 默认
UITabBarController
的引用。📌
let referenceTabBarController = HHTabBarView.shared.referenceUITabBarController
- 配置引用的
UITabBarController
📌
func setupReferenceUITabBarController() -> Void {
//Creating a storyboard reference
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
//Creating navigation controller for navigation inside the first tab.
let navigationController1: UINavigationController = UINavigationController.init(rootViewController: storyboard.instantiateViewController(withIdentifier: "FirstViewControllerID"))
//Creating navigation controller for navigation inside the second tab.
let navigationController2: UINavigationController = UINavigationController.init(rootViewController: storyboard.instantiateViewController(withIdentifier: "SecondViewControllerID"))
//Update referenced TabbarController with your viewcontrollers
referenceTabBarController.setViewControllers([navigationController1, navigationController2], animated: false)
}
- 配置
HHTabBarView
📌
//Update HHTabBarView reference with the tabs requires.
func setupHHTabBarView() -> Void {
//Default & Selected Background Color
let defaultTabColor = UIColor.white
let selectedTabColor = UIColor.init(red: 234/255, green: 218/255, blue: 195/255, alpha: 1.0)
let tabFont = UIFont.init(name: "Helvetica-Light", size: 14.0)
//Create Custom Tabs
let t1 = HHTabButton.init(withTitle: "Calendar", tabImage: UIImage.init(named: "Calendar")!, index: 0)
t1.titleLabel?.font = tabFont
t1.titleLabel?.textColor = UIColor.black
t1.setHHTabBackgroundColor(color: defaultTabColor, forState: .normal)
t1.setHHTabBackgroundColor(color: selectedTabColor, forState: .selected)
let t2 = HHTabButton.init(withTitle: "Refresh", tabImage: UIImage.init(named: "Refresh")!, index: 1)
t2.titleLabel?.font = tabFont
t2.titleLabel?.textColor = UIColor.black
t2.setHHTabBackgroundColor(color: defaultTabColor, forState: .normal)
t2.setHHTabBackgroundColor(color: selectedTabColor, forState: .selected)
//Note: As HHTabButton are subclassed of UIButton so you can modify it as much as possible.
//Set Custom Tabs
hhTabBarView.tabBarTabs = [t1, t2]
//Set Default Index for HHTabBarView.
hhTabBarView.defaultIndex = 1
//Show Animation on Switching Tabs
hhTabBarView.tabChangeAnimationType = .none
//Handle Tab Change Event
hhTabBarView.onTabTapped = { (tabIndex) in
print("Selected Tab Index:\(tabIndex)")
}
}
- 在配置
📌
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//Setup HHTabBarView
setupReferenceUITabBarController()
setupHHTabBarView()
//Setup Application Window
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.rootViewController = self.referenceTabBarController
self.window?.makeKeyAndVisible()
return true
}
- 完成!
✅
待办事项[s]
- 更新 README,包含多个示例用法和截图。
您可以通过 watch 来查看 HHTabBarView 的持续更新。敬请关注。
您对这个类有什么改进的想法吗?请打开一个 问题。
致谢
您可以发送邮件到 此链接 联系。
谢谢你们!!
请查看 贡献 获取详细信息。
许可协议
MIT 许可协议(MIT)
详细信息请参阅 许可协议 文件。