选项卡栏高度和按钮大小 - 已修复?

Tab Bar Height and button size - Fixed?

我有一个自定义标签栏控制器,我想向其添加 2 个按钮。 1 个放大的中央按钮和 1 个左侧按钮,用于创建从标签栏而不是顶部导航栏启动的侧面汉堡菜单。

我打算尝试以编程方式获取标签栏高度,以便我可以设置按钮高度等。所以我阅读并尝试了以下不起作用的代码。

self.tabBarController?.tabBar.frame.size.height

我在其他地方读到标签栏总是固定的 49 像素,无论设备如何?

如果是这种情况,使用类似的东西是否安全:

menuButtonFrame.origin.y = self.view.bounds.height - (CGFloat(49) - menuButtonFrame.size.height) / 2

设置按钮的位置? (黑匣子)它的位置还不正确

还想知道标签栏按钮的默认值是多少?

像这样创建一个 UIView 并根据需要设置中心项目的高度。

然后在TabbarView Controller中。将此视图添加到标签栏 View Like this.

UITabBar.appearance().shadowImage = UIImage()

        customNavBar = NSBundle.mainBundle().loadNibNamed("CustomTabBarView", owner: self, options: nil)[0] as! UIView

        bdNavBar.translatesAutoresizingMaskIntoConstraints = false

        self.tabBar.addSubview(customNavBar)

然后给自定义的Tabbar添加Constraints。

self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant:  0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant:  0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant:  0))
bdNavBar.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: NSLayoutAttribute.Height, relatedBy: .Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant:  50))        
self.tabBar.bringSubviewToFront(customNavBar)