Search code examples
iosswifttabsuitabbar

Why Tabbar that I create from MDCTabBarView() is not appear?


I try to custom tabbar by using meterial from link: https://material.io/components/tabs/ios#using-tabs

I do follow example instruction in this link but tabbar is not appear.

This picture is tabbar that I want enter image description here

This is my code

override func viewDidLoad() {
    super.viewDidLoad()
    
    let tabBarView = MDCTabBarView()
    tabBarView.items = [
      UITabBarItem(title: "Recents", image: UIImage(named: "phone"), tag: 0),
      UITabBarItem(title: "Favorites", image: UIImage(named: "heart"), tag: 0),
    ]
    tabBarView.preferredLayoutStyle = .scrollable // or .fixed
    view.addSubview(tabBarView)
    // Configure constraints

    // Do any additional setup after loading the view.
}

My result:

enter image description here


Solution

  • You should give it a frame or set constraints

    tabBarView.frame = CGRext(x:0,y:200,320,50)
    view.addSubview(tabBarView)