`

swift -> UITabBarController 底部tab多ViewController

 
阅读更多

* 结果显示如下 


 

 

 

RootTabBar.swift

import UIKit

let screenHt:CGFloat = UIScreen.main.bounds.height;
let screenWh:CGFloat = UIScreen.main.bounds.width;

class RootTabBar: UITabBarController{
    

    override func viewDidLoad() {
        super.viewDidLoad()
        //
        let nav_1 = Page_1()
        nav_1.tabBarItem = UITabBarItem(title: "首页", image: #imageLiteral(resourceName: "icon_1"), selectedImage: #imageLiteral(resourceName: "icon_1_sel"))
        
        let nav_2 = Page_2()
        nav_2.tabBarItem = UITabBarItem(title: "次页", image: #imageLiteral(resourceName: "icon_2"), selectedImage: #imageLiteral(resourceName: "icon_2_sel"))
        
        let nav_3 = Page_3()
        nav_3.tabBarItem = UITabBarItem(title: "尾页", image: #imageLiteral(resourceName: "icon_3"), selectedImage: #imageLiteral(resourceName: "icon_3_sel"))
        //
        
        tabBar.tintColor = UIColor.red
        self.viewControllers = [nav_1,nav_2,nav_3]
        
        
        
    }
    
    

    
}



 

* AppDelegate.swift 

 

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = RootTabBar();
        self.window?.makeKeyAndVisible()
        return true
    }

   
    // MARK: - Core Data stack
     // MARK: - Core Data Saving support

 

}

 

 

* Page_1.swift

import UIKit
class Page_1:UIViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.red
        print("view did load in page 1");
    }
}

 

 

 

 

 

 

  • 大小: 13.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics