【问题标题】:Tab Bar Height and button size - Fixed?标签栏高度和按钮大小 - 固定?
【发布时间】:2017-01-17 16:14:25
【问题描述】:

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

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

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

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

如果是这样的话,使用类似的东西是否安全:

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

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

还想知道标签栏按钮的默认值是什么?

【问题讨论】:

标签: ios swift uitabbarcontroller tabbar


【解决方案1】:

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

然后在 TabbarView 控制器中。将此视图添加到标签栏视图 像这样。

UITabBar.appearance().shadowImage = UIImage()

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

        bdNavBar.translatesAutoresizingMaskIntoConstraints = false

        self.tabBar.addSubview(customNavBar)

然后将约束添加到自定义的Tabbar。

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    相关资源
    最近更新 更多