如何隐藏我添加到UITabBar的自定义按钮?

时间:2015-09-01 07:53:58

标签: ios swift

    availableButton.frame = CGRectMake(0, screenHeight - tabBarHeight!, CGFloat(screenWidth/5.0) * 2.0, tabBarHeight!)
    availableButton.backgroundColor = FlatGreen()
    availableButton.setTitle("Turn On", forState: UIControlState.Normal)
    availableButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
    availableButton.titleLabel?.font = UIFont(name: "Roboto-Bold", size: 20.0)
    self.view.addSubview(availableButton)

这是我添加到TabBarViewController的按钮。

当我隐藏我的标签栏时:

tabBarController?.tabBar.hidden = true

我也想隐藏这个按钮。

我的按钮是2个标签栏项目的宽度。

enter image description here

2 个答案:

答案 0 :(得分:3)

您已将此按钮添加到视图中,这可能是非常糟糕的工作方式。

self.view.addSubview(availableButton)

正如tabbar所在,所以它显示出来。 通过使用tabBarItem将其添加到tabbar或手动隐藏此按钮

availableButton.hidden = YES;

你的问题将得到解决。谢谢你

答案 1 :(得分:1)

payment

let tabBarContext = UnsafeMutablePointer<()>()

self.tabBar.addObserver(self, forKeyPath: "hidden", options: NSKeyValueObservingOptions.New, context:tabBarContext)