美文网首页
Swift:BaseViewController

Swift:BaseViewController

作者: 春暖花已开 | 来源:发表于2018-12-31 17:41 被阅读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)
    }
}

相关文章

网友评论

      本文标题:Swift:BaseViewController

      本文链接:https://www.haomeiwen.com/subject/rvlwlqtx.html