CustomTabBarController.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // CustomTabBarController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/10.
  6. //
  7. import UIKit
  8. class CustomTabBarController: UITabBarController {
  9. lazy var blurTabBar: UIView = {
  10. let _blurTabBar = UIView(frame: CGRect(x: 0, y: -1, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  11. _blurTabBar.isUserInteractionEnabled = true
  12. self.tabBar.addSubview(_blurTabBar)
  13. return _blurTabBar
  14. }()
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17. // 设置 tabbar 样式
  18. self.setTabBarAppearence()
  19. // 添加 tab 页
  20. self.addFoundationTab()
  21. // 默认进入页面到主页
  22. self.selectedIndex = 1
  23. }
  24. func addFoundationTab() {
  25. self.addFriendTab()
  26. self.addHomeTab()
  27. self.addCheckTab()
  28. self.addMineTab()
  29. }
  30. }
  31. extension CustomTabBarController {
  32. func setTabBarAppearence() {
  33. self.tabBar.backgroundColor = .white
  34. self.tabBar.shadowImage = UIImage.image(color: .hexStringColor(hexString: "#EEEEEE"), size: CGSize(width: QSLConst.qsl_kScreenW, height: 1))
  35. }
  36. }
  37. extension CustomTabBarController: UITabBarControllerDelegate {
  38. override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
  39. switch item.tag {
  40. case 0:
  41. gravityInstance?.track(QSLGravityConst.tab_friend)
  42. break
  43. case 1:
  44. gravityInstance?.track(QSLGravityConst.tab_location)
  45. break
  46. case 2:
  47. gravityInstance?.track(QSLGravityConst.tab_message)
  48. break
  49. case 3:
  50. gravityInstance?.track(QSLGravityConst.tab_mine)
  51. break
  52. default:
  53. break
  54. }
  55. }
  56. }
  57. extension CustomTabBarController {
  58. /// 添加 好友 Tab
  59. func addFriendTab() {
  60. let imageInsets = UIEdgeInsets.zero
  61. let titlePostion = UIOffset(horizontal: 0, vertical: 0)
  62. let vc = QSLFriendController()
  63. self.addChildViewController(childVc: vc, title: "好友", image: "tab_friends_normal", selectedImage: "tab_friends_selected", imageInsets: imageInsets, titlePosition: titlePostion, index: 0)
  64. }
  65. /// 添加 主页定位 Tab
  66. func addHomeTab() {
  67. let imageInsets = UIEdgeInsets.zero
  68. let titlePostion = UIOffset(horizontal: 0, vertical: 0)
  69. let vc = QSLHomeController()
  70. self.addChildViewController(childVc: vc, title: "定位", image: "tab_location_normal", selectedImage: "tab_location_selected", imageInsets: imageInsets, titlePosition: titlePostion, index: 1)
  71. }
  72. /// 添加 消息 Tab
  73. func addCheckTab() {
  74. let imageInsets = UIEdgeInsets.zero
  75. let titlePostion = UIOffset(horizontal: 0, vertical: 0)
  76. let vc = QSLMessageController()
  77. self.addChildViewController(childVc: vc, title: "消息", image: "tab_message_normal", selectedImage: "tab_message_selected", imageInsets: imageInsets, titlePosition: titlePostion, index: 2)
  78. }
  79. /// 添加我的 Tab
  80. func addMineTab() {
  81. let imageInsets = UIEdgeInsets.zero
  82. let titlePostion = UIOffset(horizontal: 0, vertical: 0)
  83. let vc = QSLMineController()
  84. self.addChildViewController(childVc: vc, title: "我的", image: "tab_mine_normal", selectedImage: "tab_mine_selected", imageInsets: imageInsets, titlePosition: titlePostion, index: 3)
  85. }
  86. }