Swift完全自定义Tabbar

先创建CusTomTabBar.swift文件,之后代码如下:

//tabbar高度

let tabBarViewHeight: CGFloat = 60

//tabbar颜色

let tabBarBackColor:UIColor = UIColor.black

//用来装imageView的数组

var tabImgViews = [UIImageView]()

var imgArr = ["homePage", "mall" ,"personal"]

var imgSelArr = ["homePage_Se", "mall_Se", "personal_Se"]

var barTitleArr = ["首页","商城","个人"]

var tabBarView = UIView()

override func viewDidLoad()

{

super.viewDidLoad()

self.view.backgroundColor = UIColor.white

self.tabBar.isHidden = true

//初始化控制器加入viewControllers

initControllers()

//自定义tabbar

customTabBar()

}

func customTabBar() -> Void

{

tabBarView = UIView(frame: CGRect(x: 0, y: SCREEN_HEIGHT - tabBarViewHeight, width: SCREEN_WIDTH, height: tabBarViewHeight))

tabBarView.backgroundColor = tabBarBackColor

self.view.addSubview(tabBarView)

for index in 0.. Void

{

let indexSel = obj.tag - 100

//对应选中的控制器

self.selectedIndex = indexSel

for index in 0.. Void

{

let firstTabView = UIStoryboard.init(name:"FirstPage" , bundle: nil).instantiateViewController(withIdentifier: "FirstPageViewController")

let secondTabView = UIStoryboard.init(name:"SecondPage" , bundle: nil).instantiateViewController(withIdentifier: "SecondPageViewController")

let thirdTabView = UIStoryboard.init(name:"ThirdPage" , bundle: nil).instantiateViewController(withIdentifier: "ThirdPageViewController")

var viewArr = [firstTabView, secondTabView, thirdTabView]

var viewCtlArr = [AnyObject]()

for index in 0..

你可能感兴趣的:(Swift完全自定义Tabbar)