Search code examples
swiftuitabbarios13

Change UIITabbar width ios13 swift


I had this piece of code which worked perfectly prior to ios13 :

override func viewWillLayoutSubviews() {
     super.viewWillLayoutSubviews()

     var newFrame = tabBar.frame
     newFrame.size.width = self.view.bounds.width - 420
     tabBar.frame = newFrame

 }

but now it does nothing on ios13 running ipad. I have also tried using an extention and creating my own CustomTabBar and change the width from sizeThatFits() method, but this method ONLY CHANGES THE HEIGHT and when trying to change the width of the tabbar it does nothing


Solution

  • change it to this

    override func viewDidLayoutSubviews() {
         super.viewDidLayoutSubviews()
    
         var newFrame = tabBar.frame
         newFrame.size.width = self.view.bounds.width - 420
         tabBar.frame = newFrame
    
     }
    

    this works in Objective-C like so, just tested it:

    - (void)viewDidLayoutSubviews {
      [super viewDidLayoutSubviews];
    
      CGRect newFrame = self.tabBar.frame;
      newFrame.size.width -= 200;
      self.tabBar.frame = newFrame;
    
    }
    

    should work the same in Swift, although i have no idea why in the world you would ever want to do this and it won't do anything other than shift the tabbar buttons to the left