I just finished designing a application that uses a top bar that toggles between three UIViewControllers. My first thought was to use a UITabBarController, since it works very simular.
However, the tabBar is at the bottom and in my PSD, it's at the top. Is there anyway I can change it? I see in the library I can drag in a UITabBar, but I don't know how to get it to change pages from there.
Please help!
Coulton
Hope the below code helps
UITabBarController *tabC = [[UITabBarController alloc]init];
tabC.tabBar.frame = CGRectMake(0, 0, 320, 70);
NSArray *arr = [[NSArray alloc]initWithObjects:firstObj,secObj, nil];
tabC.viewControllers = arr;
[self.window addSubview:tabC.view];
Worked fine for me
I think it can be done, but you should be aware of this:
"Important: In iPhone OS 3.0 and later, you should not attempt to use the methods and properties of this class to modify the tab bar when it is associated with a tab bar controller object. Modifying the tab bar in this way results in the throwing of an exception. Instead, any modifications to the tab bar or its items should occur through the tab bar controller interface. You may still directly modify a tab bar object that is not associated with a tab bar controller."
So, in your UI (I suppose you defined it in Interface Builder), instantiate a UITabBar object (by choosing it in the IB library and dragging it to your view in IB). Choose the default position and also define the way that this tab bar autoresizes (using the size pane of the info window). Then, add an outlet to your view controller of type UITabBar, and, finally, connect the tab bar object to the tab bar outlet.
Once you have done this, in your view controller's viewDidLoad method you can customize any property of the tab bar that you want to.
Related
i have a simple ios implementation. There is a tableviewcontroller embedded in a navigationcontroller and a qlviewcontroller in this implementation, navigationcontroller is embedded in a tabbarcontroller too.
Actual tab lists a lot of image files, if a cell is selected in the tableviewcontroller, a qlpreviewcontroller will be instantiated and image file will be shown. another tab shows only settings of app.
i have subclassed the qlpreviewcontroller. The instance of this subclass will be created with the following code part;
XYQLPreviewController *qlpvc = [[XYQLPreviewController alloc] init];
qlpvc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:qlpvc animated:YES];
i want to hide tabbar in the preview controller so that there is enough place to preview.
these all work very well with ios 6 and below but with ios 7 i have the following problems;
Back button of navigation bar in qlpreviewcontroller doesnt respond, its not clickable.
if i back navigate with this new cool slide transition of ios 7, ta ta my tabbar got lost, i see only a white layer at the tabbar not my cool tabbar.
i see the following log message in log screen,if i select an image file and instantiate the subclass of previewcontroller.
"Container view is expected to be populated at this point"
what a problem can it be , i have no idea.
Please help.
PS:i have only a xib file not the storyboard.
If you want to hide the tab bar, I would say your best bet is to present the preview controller as a modal instead of pushing it onto the stack. Then when the user closes it (instead of hits back), it will bring them back to the tab bar view.
[self.navigationController presentViewController:qlpvc animated:YES completion:nil];
I'm currently creating an ipad application.
the idea is to have a toolbar at the top and a tabbar at the bottom.
The toolbar has to be visible on all tabs, so it won't disappear.
I was thinking about having a UIViewController as the main view and put the tool bar in there.
Then adding the uitabbarcontroller to that main view controller, but i'm not sure how to do that.
At the moment i have my tabbarcontroller as the main view and added the toolbar to every tab.
Can anyone help?
Thanks
The Tab Bar Controller should be at the root. What you can do is create a method that returns a propertly configured toolbar & add it to each of the view controller's viewDidLoad (either by using a category method, inheriting a common UIViewController subclass, or simply via a C-style factory method.
This way your hierarchy isn't flipped, and the tab bar is at the root like it should be.
How do I make a tab bar transparent in cocoa touch?
Now with iOS 5 you can change the UITabBar appearance to make only the background transparent with a simple line of code:
[[UITabBar appearance] setTintColor:[[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.2]];
Since UITabBar is a subclass of UIView, have you tried adjusting its alpha property?
Note that if you are trying to modify a tab bar associated with a UITabBarController, you should consider this warning from Apple, located in the reference for UITabBar:
Important: In iOS 3.0 and later, you
should not attempt to use the methods
and properties of this class to modify
the tab bar when it is associated with
a tab bar controller object. Modifying
the tab bar in this way results in the
throwing of an exception. Instead, any
modifications to the tab bar or its
items should occur through the tab bar
controller interface. You may still
directly modify a tab bar object that
is not associated with a tab bar
controller.
In iPhone OS 3.0, you can set the toolbar items of a UINavigationController using the setToolbarItems:animated: method. However, this requires you pass in an array of UIToolbarItems. While I could programmatically create these toolbar items, I'd rather create them in Interface Builder if possible.
With this in mind, I have created a UIToolbar in "MyGreatViewController.xib" and have populated it with the wanted toolbar items. Then, in "MyGreatViewController.m", I get the items from the toolbar and pass them to setToolbarItems:animated::
- (void)viewDidLoad {
[super viewDidLoad];
[self setToolbarItems: [toolbar items]];
}
...where toolbar is an IBOutlet referring to the UIToolbar.
Is this a good approach? Is there a better way to accomplish this? Should I just create the items programmatically?
I don't know if this is documented anywhere, but I've found that in Interface Builder, if you enable the navigation controller's toolbar, you can drag bar items to your view controller, and they will automagically show up in the navigation controller's toolbar.
For example, here's what we can do (using Xcode 3.2 on Snow Leopard):
File->New Project.... Choose Navigation-based Application and create the project.
Open MainWindow.xib in Interface Builder.
Select the Navigation Controller, and in the Attributes inspector, check the "Shows Toolbar" box. This will cause a Toolbar object to appear.
Drag a Bar Button Item from the Library to the toolbar. It will appear in the toolbar. If you check the hierarchy in the NIB, you'll see that this new item is a child of the RootViewController.
It seems that any Bar Button Items added as children of the navigation item will show up in the navigation bar, and any Bar Button Items added as children of the view controller will show up in the toolbar.
(I stumbled on this by accident. If anyone can find documentation for this behavior, or any additional info, I'd like to hear about it.)
It's a perfectly acceptable way of doing it, but do bear in mind that loading xib files is quite expensive on the iPhone, and it may well be faster to create the toolbar items programatically in your viewDidLoad method.
i'm searching for a way to disable a TabBarItem from within the ViewController of one of the TabBars Tabs. I'm even not sure if this is about the View Hierarchy or what to really search for. I tried a lot but didn't come up with a solution.
Right now I worked arround it by saving a reference to the tabbar in a singelton object when instanciating the tabbar (inside the apps delegate). But I don't think this is the best way to do it.
Thanks and Cheers,
Nils
I had the same problem and I have found a solution (but I find it a little bit dirty)
In your ViewController where you want to disable the TabBarItem, create a variable UITabBarController *myTabBarController; with property.
In the class where you manage your Tabbarcontroller put this code in the viewDidLoad:
MyViewController * vc = (MyViewController *)[navigationController.viewControllers objectAtIndex:0];// O the index of the first view controller replace it with the index of the needed viewController
vc.myTabBarController = myTabBarController; // pass your TabBarController to your ViewController
Now back to your ViewController class (MyViewController) and use this code to disable the tabBarItem:
UITabBarItem *mapTabBarItem= [[myTabBarController.tabBar items] objectAtIndex:1]; // I want to desable the second tab for example (index 1)
[mapTabBarItem setEnabled:NO];
Note that this is not the best way to do it, but it works :-)
Maybe I don't understand what you are wanting, but I have dissabled a tab bar button by going into interface builder, then selecting the tab button i want to work on (small blue highlight color only on the place holder for the picture, the small box with a ? on it) then -> Tools Menu -> Inspector -> Tab Bar Item Properties (first tab on left in the Inspector) -> then a small radio button on the bottom says "Enabled" -> deselect this. Works for me, as I use this as a simple load screen on the first tab. Hope that helps.
Kirk