美文网首页
开始一个Swift项目初始工作

开始一个Swift项目初始工作

作者: 黑化肥发灰 | 来源:发表于2017-05-18 14:16 被阅读31次

本项目假设是经典结构,即下面一个tabbar,上面几个navigationbar,采用纯代码开发。

1. 用Xcode创建一个项目,选择语言Swift

创建项目

2. 创建一个桥接文件(Header File),可以和OC混编

创建桥接文件

还要进行一些配置


C3CCAF8E-A2D9-416F-869E-77E51228F1B2.png

3. 添加一个Config文件,相当于OC当中的宏文件



把这里配置删除


Paste_Image.png

5. 启动的代理函数里面写一些界面入口

代码参考如下:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT))

    let tabbarController = UITabBarController()

    let rankController = UINavigationController(rootViewController: RankViewController())
    let searchController = UINavigationController(rootViewController: SearchViewController())
    let pushController = UINavigationController(rootViewController: PushViewController())
    let moreController = UINavigationController(rootViewController: MoreViewController())

    tabbarController.viewControllers = [rankController, searchController, pushController, moreController];

    let tabbarItem1 = UITabBarItem(title: "排行榜", image: UIImage(named: "bio"), selectedImage: UIImage(named: "bio_red"))
    let tabbarItem2 = UITabBarItem(title: "搜索", image: UIImage(named: "bio"), selectedImage: UIImage(named: "bio_red"))
    let tabbarItem3 = UITabBarItem(title: "圈子", image: UIImage(named: "bio"), selectedImage: UIImage(named: "bio_red"))
    let tabbarItem4 = UITabBarItem(title: "更多", image: UIImage(named: "bio"), selectedImage: UIImage(named: "bio_red"))

    rankController.tabBarItem = tabbarItem1
    searchController.tabBarItem = tabbarItem2
    pushController.tabBarItem = tabbarItem3
    moreController.tabBarItem = tabbarItem4

    rankController.tabBarController?.tabBar.tintColor = MAIN_RED

    self.window?.rootViewController = tabbarController
    self.window?.makeKeyAndVisible()
    return true
}

相关文章

网友评论

      本文标题:开始一个Swift项目初始工作

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