UIBarButtonItem Moves From Side to Center - ios

I have a UIToolbar with UIBarButtonItem on left and right.
First time go to screen:
Subsequent:
Anyone knows why UIBarButtonItem goes from side to center? For sure, there is no code inside my application to move UIBarButtonItem.
Note
Using code or load it from XIB both have same result.

Related

Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

I want to move the navigation controller bar to the bottom of the view controller. How can i get this done ?
I tried :
self.navigationController!.navigationBar.frame = CGRectMake(
0,
UIScreen.mainScreen().bounds.height - 50,
UIScreen.mainScreen().bounds.width,
50)
This is moving to the bottom but hiding all other controller objects and also back button is not woking.
Sujay U N,
You should not try to move the UINavigationBar provided by the embeded UINavigationController to the bottom of the screen. Trying that will obvisoulsy move all the view's below it causing all the controller objects to hide.
Workaround
Approach 1:
Consider using ToolBar :)
Toolbar is designed to be placed at the bottom of the screen. If you are using xib or storyboard you can pick toolbar from components library and place it on your ViewController's bottom and then apply autoresizing masks or constraints properly :)
Now in order to show the back button make use of UIBarButtonItems. Change the style to custom and provide it arrow image or provide default style as done.
Though now you are all set to go :) You will notice UINavigationBar at the top of your view controller. In order to get rid of it,
select your ViewController, select its TopBar property set it to none :)
Approach 2
Use UINavigationBar.
Specific about using Navigation bar and dont want to use toolbar, well you can do the same thing with UINavigationBar as well.
Drag the UINavigationBar from components library place it at the bottom of the screen. Drag the UIBarButtonItem drop it as leftBarButtonItem, change the barButtonItem image to your back image. ( Same process as UIToolBar just use UINavigationBar instead)
Understand this is not same as the navigation bar provided by the embeded NavigationController. So get rid of NavigationBar at the top of your ViewController same as I explained above here as well
Finally,
In both the cases, draw an IBoutlet from barbutton item and handle poping the viewController programmatically.
Happy coding :)

UIBarButtonItem setTitlePositionAdjustment on iOS 7 Navigation Bar

I have a UINavigationBar that has a new height of 85 and is fixed for landscape and portrait. I am adding an edit button at the top right corner but it wont stay there.
I've used the following:
[item setTitlePositionAdjustment:UIOffsetMake(0, -47) forBarMetrics:UIBarMetricsDefault];
But, if I rotate the device it moves back down 47 to the original location. If I change the metrics again it moves back to the original location. If I replace the button with another button it moves the new button to the original location, and setting the position for the new button does nothing.
I can't figure out how to move the button and get it to stay. There's no way to use constraints on the UIBarButtonItem.
You could try to put a UIView in the top right corner as the UINavigationBar child. Make the UIView have the same height as the navigation bar, and put your button inside the view. You can then add constraints for the button inside the view.

uitoolbar with icons/text similar to uitabbar

Ideally I want to use a UIToolbar but I want the icons at the bottom to appear as they would in a UITabBar meaning with icon for default and highlighted states and title beneath. I know I can drag a UIButton onto the toolbar and it will create a UIButton inside of a UIBarButtonItem, but I can't seem to manipulate the UIButton to show a title beneath? The other problem I'm having is when I set the alignment of the button in IB (in the Control section) it only changes the alignment for the default state not the highlighted state. Can anyone give me some pointers here that would be great thanks!
rc
Putting the UIButton inside a UIBarButtonItem is the best way I've found to do it. Just set the text for the button and it should show up fine. When manipulating the positioning, remember you're manipulating the position of the UIBarButtonItem and not the UIButton. Hope that helps!

How to have a "Back button style" in the UINavigatorBar / Button

I have a UINavigatorBar and dropped a button to the left top corner in the Interface Builder.
Simple question:
The Button is round, how I can set the button to a "back-style" button?
(I mean, that the left side of the button is not round, it should be a arrow).
I just put together a simple UIViewController subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear/willDisappear logic to animate the back button the way the UINavigationController does while using the leftBarButtonItem property. You'd just have to swap out the back-button PNG and change your colors in a subclass.
https://github.com/typeoneerror/BBCustomBackButtonViewController
If you want the back button to go back to the last view in the hierarchy, just leave the button off of the top left corner, and it should show up automatically.
Otherwise, you may need to subclass UIBarButtonItem.
I think if you want to do this with a UINavigationBar that does not work in conjunction with a UINavigationController you need to create a custom view for the button that is shaped like the back button.

Button image in navigation bar has different appearance. Why?

I'm trying to put a UIBarButtonItem with a custom image on a UINavigationBar. When I do however, the image doesn't look right. I want the button on the navigation bar to look like the one below it.
(This is a screenshot from the simulator, by the way, not Interface Builder)
I created the custom UIBarButtonItem by creating a UIButton, using the cog-wheel image as a background, and then simply dragging it to the the right bar button item place in Interface Builder. Seeing as creating a UIBarButtonItem programmatically with the aforementioned UIButton as its 'custom view' (-initWithCustomView) has the same result, I believe this is what is happening as well.
What I don't understand is why the button image lost its nice edges and color gradient when I added it to the navigation bar wrapped in a bar button item. Can anyone tell me?
Thanks in advance.
The image hasn't changed. It is the same. Its just that when put on different backgrounds, it is showing differently. You should consider increasing the contrast.

Resources