Files

65 lines
1.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppTab.swift
// suixinkan
//
import UIKit
/// Tab
enum AppTab: String, CaseIterable, Hashable {
case home
case orders
case statistics
case profile
var title: String {
switch self {
case .home: "首页"
case .orders: "订单"
case .statistics: "数据"
case .profile: "我的"
}
}
var selectedImageName: String {
switch self {
case .home: "tab_home_selected"
case .orders: "tab_order_selected"
case .statistics: "tab_data_selected"
case .profile: "tab_profile_selected"
}
}
var unselectedImageName: String {
switch self {
case .home: "tab_home_unselected"
case .orders: "tab_order_unselected"
case .statistics: "tab_data_unselected"
case .profile: "tab_profile_unselected"
}
}
/// TabBarItem
func makeTabBarItem() -> UITabBarItem {
let unselectedImage = UIImage(named: unselectedImageName)?.withRenderingMode(.alwaysOriginal)
let selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)
let item = UITabBarItem(title: title, image: unselectedImage, selectedImage: selectedImage)
item.accessibilityIdentifier = "main.tab.\(rawValue)"
return item
}
/// Tab
func makeRootViewController() -> UIViewController {
switch self {
case .home:
return HomeViewController()
case .orders:
return OrdersViewController()
case .statistics:
return StatisticsViewController()
case .profile:
return ProfileViewController()
}
}
}