本项目假设是经典结构,即下面一个tabbar,上面几个navigationbar,采用纯代码开发。
1. 用Xcode创建一个项目,选择语言Swift
![](https://img.haomeiwen.com/i548341/7b6f6661a7ed9c38.png)
2. 创建一个桥接文件(Header File),可以和OC混编
![](https://img.haomeiwen.com/i548341/15de500a8daa4e66.png)
还要进行一些配置
![](https://img.haomeiwen.com/i548341/17fa43a95ca16480.png)
3. 添加一个Config文件,相当于OC当中的宏文件
![](https://img.haomeiwen.com/i548341/f6920913100e3ebf.png)
![](https://img.haomeiwen.com/i548341/d6b7c640da1e90ce.png)
把这里配置删除
![](https://img.haomeiwen.com/i548341/02391ae81b534075.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
}
网友评论