Swift初学 创建TabBarViewController

1.先创建一个MainTabBarVC 继承 UITabBarController
2.AppDelegate.swift 文件代码

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        let rootVC = MainTabBarVC()
        self.window?.rootViewController = rootVC
        self.window!.makeKeyAndVisible()
        return true
    }

3.TabBarViewController.swift 代码

class MainTabBarVC: UITabBarController {

    var _backView:UIView? = nil
    var items:NSArray = []
    let nameArr = ["游戏","开服","礼包","我的"]
    let picArr = ["game","ic_home_normal","gift","mine"]
    let picSelectArr = ["gameSelected","ic_home_checked","giftSelected","mineSelected"]
    
    var navVCArr:[NSObject] = [NSObject]()
    var nav:UINavigationController = UINavigationController()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.CreatTabBar()
        
    }

    func CreatTabBar() {
        _backView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 49))
        
        for M in 0..

感谢
图片.png

你可能感兴趣的:(Swift初学 创建TabBarViewController)