Swift:BaseViewController
2018-12-31 本文已影响36人
春暖花已开
UITabBarController
import UIKit
class YQTabBarVC: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
addChild(YQUpdateMainVC(), title: "更新", imageName: "bottom_icon_government")
addChild(YQDiscoveryMainVC(), title: "发现", imageName: "bottom_icon_life")
addChild(YQBookMainVC(), title: "书架", imageName: "main_normal")
addChild(YQMineMainVC(), title: "我的", imageName: "bottom_icon_mine")
}
func addChild(_ viewController: UIViewController, title: String, imageName: String) {
let navVC = YQNavigationVC(rootViewController: viewController)
viewController.tabBarItem.title = title
viewController.tabBarItem.setTitleTextAttributes([.foregroundColor : UIColor(hexString: "EC4A52")!], for: .selected)
viewController.tabBarItem.setTitleTextAttributes([.foregroundColor: UIColor.gray], for: .normal)
viewController.tabBarItem.image = UIImage(named: imageName)
viewController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
addChild(navVC)
}
}
UINavigationController
import UIKit
class YQNavigationVC: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count > 0 {
viewController.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
}