iOS 开发每天分享优质文章

Swift 搭建App前期框架

2017-06-09  本文已影响0人  isletn

学习一门语言如何快速上手?当然是动手啦!本文教你怎样使用纯代码搭建项目前期的基本框架。自己写一个小项目,练练Swift吧!

class ZTabBarConfigure: NSObject {
    func configureZTabBarController() -> UITabBarController {
        let zTabBarController: UITabBarController = UITabBarController()
        
        let v1 = OneViewController()
        v1.title = "Home"
        v1.tabBarItem = UITabBarItem (title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home"))
        let nav1: UINavigationController = UINavigationController(rootViewController: v1)
        
        let v2 = TwoViewController()
        v2.title = "Mine"
        v2.tabBarItem = UITabBarItem.init(title: "Mine", image: UIImage.init(named: "Mine"), selectedImage: UIImage.init(named: "Mine"))
        let nav2: UINavigationController = UINavigationController(rootViewController: v2)
        
        let tabArr = [nav1,nav2]
        zTabBarController.viewControllers = tabArr
        return zTabBarController
    }
}
func setupWindow() {
        window = UIWindow.init(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        window?.makeKeyAndVisible()
        let zTabBarConfigure: ZTabBarConfigure = ZTabBarConfigure()
        let zTabBarController: UITabBarController = zTabBarConfigure.configureZTabBarController()
        window?.rootViewController = zTabBarController
        
        UITabBar.appearance().tintColor = UIColor.red
    }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        setupWindow()
        return true
    }

OK,大功告成,模拟器上跑一下,没毛病。

image.png

优秀的开源库

上一篇 下一篇

猜你喜欢

热点阅读