I'd like to put a search bar in my navigation bar, like safari has. If I add a UISearchBar to my view, it ends up underneath the navigation bar instead. How can I put a search bar in (not under) a unnavigationbar?
Try putting UISearchBar or UITextField in titleView of UINavigationItem and then set this in topItem of navigation bar.
Refer to human interface guideline to confirm that it is allowed.
I do it this way:
UISearchBar * navSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 232, 44)];
navSearchBar.delegate = self;
self.navigationItem.titleView = navSearchBar;
[navSearchBar release];
I hope it helps!
A navigationBar is mostly used to navigate a view hierarchy. If all you need is a search bar on the top of the page, why wont you just use a regular searchBar with a background similar to the navigationBar?
That way you will have much more control on the layout of the search bar, and you won't have to deal with the navigationBar.
By the way, this is probably the way the safari app actually work - it doesn't place the searchBar inside a navigationBar. You can see this by the fact that the searchBar is scrolled and doesn't stay on top.
Related
I have an issue, when I set the translucent box off on a TabBar, there is something blocking some of my view.
It looks like it's a sort of extra tab bar or I don't even know. I'm using storyboard.
Please see the images attached:
With Translucent (OFF - NO):
With Translucent (ON or YES):
Does anybody know why it looks like this?
Thanks
PS: Which tabBar do you guys like? Black or this one:
This happens in iOS7 when you set tabBar.translucent to NO. iOS is trying to be smart and say "hey the tabbar is not translucent so we better push everything up on top of it". Fix it by setting the extendedLayoutIncludesOpaqueBars property of the view controller inside the navigation controller which is inside the tabbar controller to YES.
Example (not actually ran):
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tabBar.translucent = NO;
UIViewController *viewController = [[UIViewController alloc] init];
viewController.extendedLayoutIncludesOpaqueBars = YES; // <-- This is important!!!!!!
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
tabBarController.viewControllers = #[navigationController];
Source: https://web.archive.org/web/20160405135605/https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
And BTW, I like the non-translucent tabbar the best.
Edit
As Andy mentioned below, this flag does not have to be set in code. You can set it in IB if that's what you use.
As mentioned here you have to set barTintColor to something you want to change the color.
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the tab bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the tab bar has UIBarStyleBlack style, white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined.
Something that I used for my project
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
self.tabBarController.tabBar.translucent = NO;
I have acontroller with TableView and both translucent NavigationBar and translucent TabBar. In this situation using viewController.extendedLayoutIncludesOpaqueBars = YES; causes a problem of both bars overlaping my table view. It can be managed by setting viewController.edgesForExtendedLayout = UIRectEdgeBottom; which results in TableView hiding only behind Tab Bar.
It looks like you've set up the view controller's view so that its bottom is at the same position as the top of the tab bar, when it should be at the bottom of the screen. If you do that, then your content will appear correctly (content visible through the tab bar or not) whether the tab bar is set to translucent or not.
For those who actually want a translucent Tabbar and a table view (or collection view for me) that can be seen behind, here is my solution for ios 7/8:
If you are using constraints, you should add one on the bottom of the table view to the "Bottom Layout Guide" so your tableview stops before the Tabbar. This is an example with Storyboard, but it can be done in code as well.
Then you just need to make sure you can still see the table view behind the Tabbar by settings the "clipsToBounds" property to NO.
self.mytableview.clipsToBounds = NO;
This is my solution, hope it helps.
I don't think the currently accepted answer is correct. You don't need to extend the layout under opaque bars to solve the issue.
There is no code provided in the OP, but it is likely that the bottom of the view containing the items is constrained to the bottom of its superview, which would have taken the items underneath the translucent tab bar. To prevent this, a manual inset could have been set from the bottom. In short, the superview extends underneath the translucent bar and so did its subviews.
As soon as the tab bar was made opaque, the root view (or the superview) only extended until the top of the tab bar.
The 'more' correct fix would be to just remove the manual inset of content, not extending the view under opaque bars.
I would like the user to be able to edit the title of the navigation bar. I feel like I've seen it in an app before. Is this possible?
If you are using a UINavigationController then play around with
self.navigationItem.titleView = // UITextView
You will have to customize your navigationBar and add the UITextField as as subView, and place it accordingly.
I have a simple question (maybe not a simple answer). Currently I have an iPhone app and I tab bar and navigation set up on it. When I set the self.title it puts it in both the tab bar and the navigation bar. I was wondering if there was a way to have a different title on the navigation bar and tab bar?
You're setting the title of the whole view, which in turn automatically sets the title of the tabBar and the nav controller. To set the title of them each individually,
You first set the nav bar by accessing the nav item:
[[self navigationItem] setTitle:(NSString *)];
Then you set the tabBar title by accessing the tab bar item and setting its title like so:
[self.tabBarItem setTitle:(NSString *)];
Good Luck!
use self.navigationItem.title for the navigation bar.
This is a common mistake and happened to me so many times.
To get around this, every ViewController comes with a navigationItem property giving you even further options.
Use following line inside your ViewControllers to set the title:
self.navigationItem.title = #"Your Desired Title";
I have an application with a tab bar and a navigation bar. I push a view controller that is used to show photos, one at a time. It initially shows the bars and forward/back controls; after a delay, these hide, using setNavigationBarHidden:animated: and a custom transform (CGAffineTransformMakeTranslation) on the tab bar. This works, but the view controllers view , which shows the photo, leaps up and down. The same is true if I leave the tab bar out of the equation.
How can I prevent the UINavigationBar from moving my view around? I would like the photo to stay fixed in the screen, with the nav bar dropping down over the top segment of it.
Had this issue and fixed it with a class that inherited from UINavigationController
-(void)viewWillAppear:(BOOL)animated
{
self.navigationBar.translucent = YES;
}
Worked great for me, didn't had to set style to UIBarStyleBlackTranslucent. So it did kept my colors.
[[navigationController navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
[[navigationController navigationBar] setAutoresizesSubviews:NO];
this seemed to do the trick for me!
I know this is an old question, but I accomplished that by disabling 'Autoresize Subviews' in Interface Builder
I haven't been able to find a proper way to handle this except to set the navigationBar style to translucent as in:
theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Other than creating another navigation bar and adding buttons to them, that's the best (and it seems to be what Apple does as well in it's Photo app)
In my application, the view below navigation controller moves up and is visible below the navigation bar as it's becoming transperant after adding a barbuttonitem programmatically to the navigation controller which I'm adding to view through an xib.
This' the way I'm adding it:
UIBarButtonItem *comment = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self
action:#selector(buttonPressed)];
self.navigationItem.rightBarButtonItem = comment;
EDIT:
Ok, I quite came to know that this' happening because for all my custom cells of different type except one, I'm pushing xib files of detailedviews to navigation controller for tapped cells, but for this only one, I've created a view controller programmatically and pushing it. So as long as I don't tap and open this cell in detailview, everything works fine, but after I open this cell's detailview(which always opens fine), other cells detailviews shift.
Can anybody please address this issue?
Thanx in advance.
Check all view's frame and for testing set different color for all subviews.You will find out the problem easily. or post more detailed code.
Difference in size of viewControllers view:
If you are creating it through .XIB, then you will be having status bar in it. means your view size is 20 pixels lesser than that of the window. (320 * 460)
If you are creating it programmatically, then there will not be a status bar. Means size will be 320*480.
In this way view frame differs...
So set the size of view to 320*460 and try out...
Ok, after lot of struggling, I figured it out that what causes the problem is that since I'm using Three20 library to show facebook-like photos, the TTPhotoviewcontorller in it changes the bar style of the navigation bar of your navigation controller to UIBarStyleBlackTranslucent, and what you need to do is to reset the bar style property to UIBarStyleDefault. You should try to call
self.navigationController.navigationBar.bar = UIBarStyleDefault;