MeTabBarController.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // MeTabBarController.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/6/26.
  6. //
  7. import UIKit
  8. import ReactorKit
  9. import RxCocoa
  10. import RxSwift
  11. final class MeTabBarController: UITabBarController, View {
  12. // MARK: Constants
  13. fileprivate struct Metric {
  14. static let tabBarHeight = 50.f
  15. }
  16. let bgView = UIView.init().then {
  17. $0.backgroundColor = .db_tbbg
  18. }
  19. // MARK: Properties
  20. var disposeBag = DisposeBag()
  21. init(
  22. reactor: MainTabBarViewReactor,
  23. advancetViewController:MeTraineeListViewController,
  24. officialViewController:MeTraineeListViewController
  25. ) {
  26. defer { self.reactor = reactor }
  27. super.init(nibName: nil, bundle: nil)
  28. self.viewControllers = [advancetViewController,
  29. officialViewController]
  30. .map{ (viewController) -> UINavigationController in
  31. let navigationController = MainNavigationController(rootViewController: viewController)
  32. // navigationController.tabBarItem.imageInsets.top = 5
  33. // navigationController.tabBarItem.imageInsets.bottom = 5
  34. navigationController.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
  35. return navigationController
  36. }
  37. // 获取当前 tabBar 的选中项
  38. if let items = self.tabBar.items {
  39. for item in items {
  40. // 设置选中项的标题字体和颜色
  41. item.setTitleTextAttributes([NSAttributedString.Key.font: NYFont.SysFont.sys_10,
  42. NSAttributedString.Key.foregroundColor: UIColor("#30B05C") as Any],
  43. for: .selected)
  44. }
  45. }
  46. self.tabBar.insertSubview(bgView, at: 0)
  47. self.selectedIndex = 1
  48. self.tabBar.barTintColor = .db_tbbg
  49. self.tabBar.tintColor = UIColor("#30B05C")
  50. }
  51. required init?(coder aDecoder: NSCoder) {
  52. fatalError("init(coder:) has not been implemented")
  53. }
  54. // MARK: Configuring
  55. func bind(reactor: MainTabBarViewReactor) {
  56. self.rx.didSelect
  57. .scan((nil, nil)) { state, viewController in
  58. return (state.1, viewController)
  59. }.subscribe(onNext: { (fromVc,toVc) in
  60. // if fromVc == toVc || fromVc == nil {
  61. // TogetherDataManager.refreshDataForTab(toVc, true)
  62. // } else {
  63. // TogetherDataManager.refreshDataForTab(toVc, false)
  64. // }
  65. // if TogetherDataManager.homePageController(toVc) == nil {
  66. // TogetherDataManager.referenceDate = Date()
  67. // }
  68. }).disposed(by: disposeBag)
  69. }
  70. override func viewDidLayoutSubviews() {
  71. super.viewDidLayoutSubviews()
  72. if #available(iOS 11.0, *) {
  73. self.tabBar.height = Metric.tabBarHeight + self.view.safeAreaInsets.bottom
  74. } else {
  75. self.tabBar.height = Metric.tabBarHeight
  76. }
  77. self.bgView.frame = CGRect(x: 0, y: 0, width: Int(self.view.width), height: Int(self.tabBar.height))
  78. self.tabBar.bottom = self.view.height
  79. }
  80. }