# Exploring Swift: building a tab bar entirely in code

Language: en
Canonical: [Exploring Swift: building a tab bar entirely in code](<https://allluckly.cn/en/journal/2015-08-25-exploring-swift-building-a-tab-bar-entirely-in-code/>)
中文：[中文 HTML](<https://allluckly.cn/swift/Swift%E5%88%9D%E6%8E%A2%E4%B9%8B%E7%BA%AF%E4%BB%A3%E7%A0%81%E5%86%99tabBar>)
English: [English HTML](<https://allluckly.cn/en/journal/2015-08-25-exploring-swift-building-a-tab-bar-entirely-in-code/>)
Published: 2015-08-25T00:00:00+08:00
Modified: 2026-10-23T10:34:10+08:00
Author: [Bison](<https://allluckly.cn/about/>)

Builds a Zhe800-inspired tab bar using early Swift syntax. It creates child view controllers, assigns titles and icons, and adds them to the system tab bar, illustrating how to organise a navigation structure programmatically.

Originally credited to Bison. Content is retained as published.

English translation of the [Chinese original](<https://allluckly.cn/swift/Swift%E5%88%9D%E6%8E%A2%E4%B9%8B%E7%BA%AF%E4%BB%A3%E7%A0%81%E5%86%99tabBar>), translated on 2026-10-23. The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

**Before you read** This technical note dates from 2015–2017. The examples have not been rerun as part of this archive update. Published in 2015 and written using early Swift syntax.

> “Enrich yourself and increase your value by continuing to learn.” Bison

The new version of my recent project is mostly finished, so I am using some spare time to learn the new Swift language. Swift is fairly easy to learn if you already know OC. Below is a Tabbar I wrote while teaching myself. Of  
 course, this is not a custom implementation. It should still meet ordinary requirements.  
 Below is a Tabbar I wrote to imitate “折800”. It has a few minor imperfections because of the images.

The code is as follows

Core code

```css
class func CusTomTabBar() ->UITabBarController{

var vc1 = Home_VC()
var vc2 = Class_VC()
var vc3 = Brand_VC()
var vc4 = Shoping_VC()
var vc5 = Personal_VC()
var nvc1:UINavigationController = LBNvc(rootViewController: vc1)
var nvc2:UINavigationController = LBNvc(rootViewController: vc2)
var nvc3:UINavigationController = LBNvc(rootViewController: vc3)
var nvc4:UINavigationController = LBNvc(rootViewController: vc4)
var nvc5:UINavigationController = LBNvc(rootViewController: vc5)
let tabbar1 = UITabBarItem(title: "首页", image: (Public .getImgView("home_tab_home_btn@2x")) , selectedImage: (Public .getImgView("home_tab_home_selected_btn@2x")))
let tabbar2 = UITabBarItem(title: "分类", image: (Public .getImgView("home_tab_saunter_btn@2x")), selectedImage: (Public .getImgView("home_tab_saunter_selected_btn@2x")))
let tabbar3 = UITabBarItem(title: "品牌团", image: (Public .getImgView("home_tab_branc_btn@2x")), selectedImage: (Public .getImgView("home_tab_branc_selected_btn@2x")))
let tabbar4 = UITabBarItem(title: "积分商城", image: (Public .getImgView("home_tab_point_btn@2x")), selectedImage: (Public .getImgView("home_tab_point_selected_btn@2x")))
let tabbar5 = UITabBarItem(title: "个人中心", image: (Public .getImgView("home_tab_personal_btn@2x")), selectedImage: (Public .getImgView("home_tab_personal_selected_btn@2x")))
nvc1.tabBarItem = tabbar1;
nvc2.tabBarItem = tabbar2;
nvc3.tabBarItem = tabbar3;
nvc4.tabBarItem = tabbar4;
nvc5.tabBarItem = tabbar5;
var tc = UITabBarController()

tc.tabBar.tintColor = UIColor .redColor()
//        tc.tabBar.backgroundImage = Public.getImgView("3.png")
tc.viewControllers = [nvc1,nvc2,nvc3,nvc4,nvc5];
return tc;
}
 
```

> [Click to download the demo](<https://github.com/AllLuckly/LBSwift_TabBar>)

![(LBSwift\_TabBar)](<https://github.com/AllLuckly/LBSwift_TabBar/blob/master/123.gif?raw=true>)

