You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
5.2 KiB
136 lines
5.2 KiB
![]()
2 years ago
|
//
|
||
|
// HomeTabBarController.swift
|
||
![]()
1 year ago
|
// FireBoltt
|
||
![]()
2 years ago
|
//
|
||
|
// Created by lemo. on 2020/3/7.
|
||
|
// Copyright © 2020 Sheldon. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
enum HomeTabBarItem: Int {
|
||
|
case health, sport, device, mine
|
||
|
|
||
|
private func controller(with viewModel: ViewModel, navigator: Navigator) -> UIViewController {
|
||
|
switch self {
|
||
|
case .health:
|
||
|
// let vc = HealthViewController(viewModel: viewModel, navigator: navigator)
|
||
![]()
2 years ago
|
let vc = HealthHomeViewControllers(viewModel: viewModel, navigator: navigator)
|
||
![]()
2 years ago
|
vc.isHiddenNavBar = true
|
||
|
return NavigationController(rootViewController: vc)
|
||
|
case .sport:
|
||
![]()
2 years ago
|
let vc = SportViewControllers(viewModel: viewModel, navigator: navigator)
|
||
![]()
2 years ago
|
return NavigationController(rootViewController: vc)
|
||
|
case .device:
|
||
![]()
2 years ago
|
let vc = DeviceViewControllers(viewModel: viewModel, navigator: navigator)
|
||
![]()
2 years ago
|
// vc.tongzhi(); 加入的目的是什么?初始化就已经跑了? 加入会导致重复执行通知
|
||
|
return NavigationController(rootViewController: vc)
|
||
|
case .mine:
|
||
|
let vc = MineViewController(viewModel: viewModel, navigator: navigator)
|
||
|
vc.isHiddenNavBar = true
|
||
|
vc.isLightStatusBar = true
|
||
|
return NavigationController(rootViewController: vc)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var image: UIImage? {
|
||
|
switch self {
|
||
![]()
1 year ago
|
case .health: return R.image.fb_icon_health_normal()
|
||
|
case .sport: return R.image.fb_icon_sport_normal()
|
||
|
case .device: return R.image.fb_icon_device_normal()
|
||
|
case .mine: return R.image.fb_icon_mine_normal()
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
var selectedImage: UIImage? {
|
||
|
switch self {
|
||
![]()
1 year ago
|
case .health: return R.image.fb_icon_health_selected()
|
||
|
case .sport: return R.image.fb_icon_sport_selected()
|
||
|
case .device: return R.image.fb_icon_device_normal()
|
||
|
case .mine: return R.image.fb_icon_mine_selected()
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
var title: String {
|
||
|
switch self {
|
||
![]()
1 year ago
|
case .health: return MultiLanguageKey_FB.healthFB.localized
|
||
|
case .sport: return MultiLanguageKey_FB.sportFB.localized
|
||
|
case .device: return MultiLanguageKey_FB.deviceFB.localized
|
||
|
case .mine: return MultiLanguageKey_FB.mineFB.localized
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func getController(with viewModel: ViewModel, navigator: Navigator) -> UIViewController {
|
||
|
let vc = controller(with: viewModel, navigator: navigator)
|
||
|
let item = UITabBarItem(title: title, image: image?.withRenderingMode(.alwaysOriginal), selectedImage: selectedImage?.withRenderingMode(.alwaysOriginal)).then {
|
||
|
$0.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: kHexColor(0x2A2A2A)], for: .normal)
|
||
![]()
2 years ago
|
$0.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: kHexColor(0x004EFF)], for: .selected)
|
||
![]()
2 years ago
|
}
|
||
|
vc.tabBarItem = item
|
||
|
return vc
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class HomeTabBarController: UITabBarController, Navigatable {
|
||
|
var viewModel: HomeTabBarViewModel?
|
||
|
var navigator: Navigator!
|
||
|
|
||
|
init(viewModel: ViewModel?, navigator: Navigator) {
|
||
|
self.viewModel = viewModel as? HomeTabBarViewModel
|
||
|
self.navigator = navigator
|
||
|
super.init(nibName: nil, bundle: nil)
|
||
|
}
|
||
|
|
||
|
required init?(coder aDecoder: NSCoder) {
|
||
|
fatalError("init(coder:) has not been implemented")
|
||
|
}
|
||
|
|
||
|
override func viewDidLoad() {
|
||
|
super.viewDidLoad()
|
||
|
makeUI()
|
||
|
bindViewModel()
|
||
|
}
|
||
|
|
||
|
func makeUI() {
|
||
|
delegate = self
|
||
|
tabBar.isTranslucent = false
|
||
![]()
1 year ago
|
tabBar.barTintColor = ThemeManagerFrieBoltt.tabBarColor
|
||
![]()
2 years ago
|
tabBar.backgroundImage = UIImage()
|
||
|
tabBar.shadowImage = UIImage()
|
||
|
tabBar.layer.shadowColor = UIColor.lightGray.cgColor
|
||
|
tabBar.layer.shadowOffset = CGSize(width: 0, height: -5)
|
||
|
tabBar.layer.shadowOpacity = 0.3
|
||
|
if #available(iOS 13, *) {
|
||
|
let lineView = UIView(frame: CGRect(x: 0, y: -1, width: tabBar.bounds.width, height: 1))
|
||
![]()
1 year ago
|
lineView.backgroundColor = ThemeManagerFrieBoltt.tabBarColor
|
||
![]()
2 years ago
|
tabBar.addSubview(lineView)
|
||
|
}
|
||
|
if #available(iOS 15, *) {
|
||
|
let bar = UITabBarAppearance.init()
|
||
![]()
1 year ago
|
bar.backgroundColor = ThemeManagerFrieBoltt.tabBarColor
|
||
![]()
2 years ago
|
bar.shadowImage = UIImage()
|
||
|
let selTitleAttr = [
|
||
|
// NSAttributedString.Key.font: itemFont,
|
||
![]()
2 years ago
|
NSAttributedString.Key.foregroundColor: kHexColor(0x004EFF)
|
||
![]()
2 years ago
|
]
|
||
|
bar.stackedLayoutAppearance.selected.titleTextAttributes = selTitleAttr
|
||
|
self.tabBar.scrollEdgeAppearance = bar
|
||
|
self.tabBar.standardAppearance = bar
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func bindViewModel() {
|
||
|
guard let viewModel = viewModel else { return }
|
||
|
let controllers = viewModel.tabBarItems.map { $0.getController(with: viewModel.viewModel(for: $0), navigator: navigator) }
|
||
|
setViewControllers(controllers, animated: false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
extension HomeTabBarController: UITabBarControllerDelegate {
|
||
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
||
|
return true
|
||
|
}
|
||
|
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
||
|
}
|
||
|
}
|