Positioning UITabBar at the top

前端 未结 9 1779
小鲜肉
小鲜肉 2020-11-28 10:30

I\'m a beginner in iOS development. My question is: is it possible to position UITabBar at the top and how? I can\'t position my UITabBar at the top of the view.

9条回答
  •  没有蜡笔的小新
    2020-11-28 10:55

    Here is a working swift 3 example of aviatorken89's code.

    1. First create a new file.
    2. Select source cocoa touch class.
    3. Designate subclass of: UITabBarController
    4. Name the class "CustomTabBarController" or whatever you'd like.
    5. Add the following code to the class.

      override func viewWillLayoutSubviews() {
          super.viewWillLayoutSubviews()
          var tabFrame:CGRect = self.tabBar.frame
          tabFrame.origin.y = self.view.frame.origin.y
          self.tabBar.frame = tabFrame
      }
      
    6. If you are using storyboard make sure to change the tab bar class to your custom class via the "Identity inspector".

提交回复
热议问题