I am developing one application.In that I need to decrease the UINavigationBar size, For that I use the below code.
CGFloat navBarHeight = 10.0f;
CGRect frame = CGRectMake(50.0f, 0.0f, 320.0f, navBarHeight);
[self.navigationController.navigationBar setFrame:frame];
But when I go to next page, that page Navigationbar also changed.But I need to change only one page. And I want to separate the back button and place before navigation bar.So for that i place one button before UINavigationBar.But I don’t perform it action.
So please tell me how to do this one.
Thanks in advance…
What you need to be aware of is that the Navigation Controller manages an entire view hierarchy. When you have ViewControllerA, in which you alter the navigation bar of the navigation controller’s height, and then push ViewControllerB onto that navigation controller’s stack, you are effectively looking at the same navigation bar. You will need to change the height back to it’s original in ViewControllerB.
I’m not sure what you mean by “Separate the back button and place before navigation bar”. Do you have a picture or could you clarify the question?
UPDATE: Based on your comment, what you are trying to achieve is possible, but a bad idea. A UINavigationController’s navigationBar spans the entire width of the screen. Regardless of the technical feasibility of shortening the width of this bar to show your button to the left of it, this arguably infringes on the HIG’s, which require standard use of standard iOS features; i.e. the navigation bar should always span the width of the device in either orientation. If you are looking to replace the standard back button with a different button, that is possible by simply replacing the leftNavigationItem, i.e.
You probably want to set hidesBackButton = YES, as well.
UPDATE 2: I tested this in a small Xcode project, and you can change the width of the navigation bar. It looks silly, but it’s possible. However, if you use a nib and set the NavigationBar property on that nib, when you add your button to the view controller’s view, you have to set the y value of the frame to a negative number to get it in line with the nav bar. Even still, setting text or target/actions on this button don’t seem to work. The navigation bar might reserve that width for itself. Removing the nav bar setting from the nib and trying again still doesn’t do it. The presence of the navigation bar (or, really, the navigation controller, most likely), seems to prevent anything else from receiving touch events in that area.