将标签栏移动到屏幕顶部

时间:2011-07-13 19:24:45

标签: ios iphone interface-builder uitabbarcontroller

我有一个标签栏控制器,正如我们所知,它显示屏幕底部的标签栏。我正在寻找一种方法将它移到顶部。我不认为我可以使用简单的UITabBar,因为我需要在其下嵌套UINavigationControllers

有没有办法将UITabBarController中的标签栏移动到屏幕顶部?

5 个答案:

答案 0 :(得分:8)

在方法" viewDidLayoutSubviews"中尝试此代码你的 UITabBarController

Swift 2.X

  self.tabbar.frame = CGRectMake(0,0,320,50) //example for iPhone 5

Swift 3.X

  self.tabbar.frame = CGRect(0,0,320,50) //example for iPhone 5

Swift 4.X

  self.tabbar.frame = CGRect( x: 0, y: 0, width: 320, height: 50)  //example for iPhone 5

答案 1 :(得分:4)

(在斯威夫特)

在TabBarViewController.swift文件中(每个人都按照自己的意愿命名了这个文件):

  • 首先:创建标签栏的IBOutlet,然后将其连接到情节提要或nib文件中的相应标签栏。

    @IBOutlet var profileTabBar : UITabBar!
    
  • 第二步:在 viewDidLoad()函数中添加此代码,以将标签栏置于所需位置(在本例中,我在导航控制器下添加de tab bar)。修改 CGRectMake 初始化程序的位置更改 x y

    // [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)
    

答案 2 :(得分:0)

我不这么认为。我唯一能想到的是使用UITabBar而不是UITabbarController ...

如果您正在考虑为为不同选项卡加载的每个视图嵌套UINavigationControllers,那么这可能是一个更好的选择。

答案 3 :(得分:0)

在 viewDidLayoutSubviews() 中把这段代码像这样

np.newaxis

答案 4 :(得分:-2)

我使用Tab Bar Controller然后我只需更改TabBar

Tab Bar Controller的{​​{1}}位置
ViewDidLoad()

这是附加所需结果的屏幕短片...... Tab bar on top in tab bar view conmtroller

注意:这是快速3 您可以自行将语法更改为swift 2. *。

相关问题