Add a UIButton as a subview to a UITabBar
You can still add the UIButton
to the UITabBarController
's main view, not in the UITabBar
though.... [myUITabBarController.view addSubview:pullButton]
Adding UIButton to UITabBar
You cannot add a UIButton
directly to a UITabBarController
. From the UITabBarController
Class Reference:
You should never access the tab bar view of a tab bar controller
directly.
Further along, the documentation reads:
Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you do not provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.
Therefore your two options are:
- Create a
UITabBarItem
(documentation) and add that. - Use a
UIToolBar
instead, but remember to addUIBarButtonItem
s.
Placing a UIButton in the same space as UITabBar (When hidden)
Tander I finally figured it out, The button was not responding because its not receiving our touch events, you see In our storyboard, the View is not connected to the viewController, and due to this when I add the button programmatically to View It would never respond, A simple line solved this
In the function
- (IBAction)doneButton:(UIBarButtonItem *)sender
Just do this
- (IBAction)doneButton:(UIBarButtonItem *)sender
{
/* Will hide or unhide the tabBar */
self.tabBarController.tabBar.hidden=YES;
[self.tabBarController setTabBarItem:nil];
UIButton *butt=[UIButton buttonWithType:UIButtonTypeCustom];
butt.backgroundColor=[UIColor redColor];
butt.frame=CGRectMake(160, 530, 93, 40);
[butt addTarget:self action:@selector(testButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.tabBarController.view addSubview:butt];
}
the self.tabBarController.view
was our culprit, not letting the touch Events pas through, glad to have figured it out
UIButton going behind Tab Bar when navigating back to parent View Controller - iOS
Okay, found the solution! instead of hiding the tabBar
by
- (BOOL)hidesBottomBarWhenPushed {
return YES;
}
hide the tabBar
by [tabBarController.tabBar setHidden:YES]
in the last viewController
. Then when navigate back, do [tabBarController.tabBar setHidden:NO];
in viewWillDisappear
.
This way the subviews
arrangement in tabBarController
stays same :)
How to push a ViewController from a UIButton that is embedded in Tab Bar Controller
So I figured it out. Turns out it was much simpler than I thought, which makes me think I was explaining myself poorly in the question. Anyway, here's the code that worked for me.
let myViewController = ViewController()
let nav = UINavigationController(rootViewController: myViewController)
self.present(nav, animated:true, completion: nil)
Related Topics
How to Convert Cgpoint in Nsvalue in Swift
Fixed Background for Part of a Site (Div) in iOS
Background Image Not Displaying Correctly in iOS
"Reached the Max Number of Texture Atlases, Can Not Allocate More" Using Google Maps
How to Change Select Box Background Without Losing The Right Arrow on Mobile Safari
How to Animate a Nslayoutconstraint in Swift
Get Path to Subdirectory in Resources Folder
Uitableviewcells Initial Load View/Display Issue
Adding an Skscene to a Uiviewcontroller
How Is a Swift Cgvector Created with Dx and Dy (Derivative)
Is There an iOS API for Accessing Call Logs
Auto Layout How to Hide 1 View in a View with 3 Equal Width Views
Are Private Frameworks Supported on iOS
-Webkit-Overflow-Scrolling: Touch' Broken for Initially Offscreen Elements in iOS7
iOS 7 Weather App Expand/Collapse Transition
Runtime Error When Using Corefoundation Objects in a Swift Nsobject Subclass
Detecting Double and Single Tap on Uitableviewcell to Perform Two Action