Move Tab Bar to top of screen

后端 未结 4 1084
一个人的身影
一个人的身影 2020-12-07 03:43

I have a Tab Bar Controller which, as we know, displays the tab bar at the bottom of the screen. I\'m looking for a way to move it to the top. I don\'t think I can use a s

4条回答
  •  情深已故
    2020-12-07 04:22

    (in Swift)

    In the TabBarViewController.swift file (everyone has named this file as he wants):

    • First: create an IBOutlet of a tab bar and then connect it to the appropiate tab bar in the storyboard or in the nib file.

      @IBOutlet var profileTabBar : UITabBar!
      
    • Second: add this code in the viewDidLoad() function to situate the tab bar where you want (in this case I add de tab bar under the navigation controller). To modify the position change x and y of CGRectMake initializer.

      // [Maybe you don't have a navigation controller] yNavBar indicates the height of the navigation bar. 
      var yNavBar = self.navigationController?.navigationBar.frame.size.height
      // yStatusBar indicates the height of the status bar 
      var yStatusBar = UIApplication.sharedApplication().statusBarFrame.size.height
      // Set the size and the position in the screen of the tab bar
      profileTabBar.frame = CGRectMake(0, yNavBar! + yStatusBar + profileTabBar.frame.size.height, profileTabBar.frame.size.width, profileTabBar.frame.size.height)
      

提交回复
热议问题