Reputation: 271584
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)
This is the button that I added to my TabBarViewController
.
When I hide my Tab Bar:
tabBarController?.tabBar.hidden = true
I want this button to be hidden as well.
My button is the width of 2 tab bar items.
Upvotes: 0
Views: 274
Reputation: 1003
You have added this button to your view, perhaps this is very bad approach to work.
self.view.addSubview(availableButton)
as tabbar is behind it so it shows. Either ad this to tabbar by using tabBarItem or hide this button manually
availableButton.hidden = YES;
Your problem will be solved.Thank you
Upvotes: 3
Reputation: 31339
let tabBarContext = UnsafeMutablePointer<()>()
self.tabBar.addObserver(self, forKeyPath: "hidden", options: NSKeyValueObservingOptions.New, context:tabBarContext)
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
if context == tabBarContext && keyPath == "hidden"{
let newChange = change[NSKeyValueChangeNewKey] as! Int
self.availableButton.hidden = (newChange == 1) ? true :false
}
}
Upvotes: 1