UIBarButtonItem setTitlePositionAdjustment on iOS 7 Navigation Bar - ios

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.

Related

move navigationBar's left and right barButtonItem's vertically upwards

I am trying to move my navigation bar's left and right barButtonItem's upwards vertically without any success. I can manage to move the title view up but using the same method for the barButtonItem's doesn't do anything.
The effect I'm trying to achieve is what is used on the Bookmarks page of safari:
I'm hoping to achieve this without any subclassing of the navigationBar so that I can maintain the translucency.
My approach was to add UIView's to the navigationBar directly in IB for the leftBarButtonItem, Title and rightBarButtonItem. This works fine for the title and I'm able to add the Title and segmentedControl. The problem is when I add the left and right barButtonItem's I am not able to move them vertically above my segmented control. I am using the following code to try to move the barButtonItem's vertically in viewDidLoad():
self.navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(-15, for: UIBarMetrics.defaultPrompt)
self.navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(-15, for: UIBarMetrics.compactPrompt)

Embed a UIImageView in a bar widget either at the top or bottom of the screen

The navigation bar can take a UIImageView via the titleView property,
for example
self.navigationItem.titleView, and the The UIImageView can be animated.
Unfortunately, as per the documentation "Custom title views are centered on the navigation bar and may be resized to fit". This resizing makes it unsuitable for me.
My goal is to animate a UIImageView in something like a navigation bar, tab bar or toolbar. In other words I want to animate UIImageView in a bar that is always visible in a view.
How would I do this (using swift)?
A possible solution is to create a UIBarButtonItem with a UIImageView in the constructor and set the left or right button in the navigator bar to the animate button item.

Using Autolayout, unable to move the navigation bar down 20px

I have a UITabBarController which has four tabs. One of those tabs opens a my results screen (a UITableViewController).
On showing this screen, I want to move the UINavigationBar down 20px (to make room for a custom UIStatusBar which I show on all screens).
On all my other screens, I add some code to the viewWillAppear method to change the self.navigationController.navigationBar.frame.origin.y to 20.
but these are all "non-root" screens (i.e. a pushed view with a back button).
However on THIS screen the UINavigationBar must be initially visible, even though it is the root view. I use the same code, but it doesn't move the view down.
I'm assuming autolayout is moving it back into position, so I tried adding this code into viewWillLayoutSubviews and viewDidLayoutSubviews. But when I do this the navigationbar doesn't move down until the first time the tableview is scrolled.
What do I need to do to force the navigationBar to move down (and stay down) before the screen appears?
Are you using storyboards? Set the Y in storyboards to 20, Make your viewcontroller implement UINavigation bar, then add this code:
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar{
return UIBarPositionTopAttached;
}
This will tell the app that the navigation bar is to be attached, it will remain at 20px but extend the background all the way up.. So essentially it'll look like it's at y = 20.

Positioning a bar button in toolbar at center in storyboard (in Portrait & Landscape)

I have a toolbar in UIView form and a bar button to the right which has a huge caption "Add blah to blah" and no left bar button, The right bar button segues to multiple screens depending on UIform value on right button click.
I now need to add a button in center that does something else. I want this button to be in center irrespective of portrait or landscape. I added fixed space on either side to keep the center button in center. But the button goes to left in landscape mode, though it looks good in portrait.
Had it been programmatically adding, something like below might have worked
self.toolbarItems = [NSArray arrayWithObjects:flexibleSpaceBarButton, centerButton, flexibleSpaceBarButton, bigCaptionButton2, nil];
But most of the things have been done on storyboard and this new button needs to be in center. Is there a easy way to center a button in toolbar on a UIView in storyboard in both landscape and portrait mode ?
This is a toolbar button at the bottom of UIView form
Thanks
Drag flexible space objects from the object library and insert them on either side of the button you want centered.

UIBarButtonItem moves inward after altering it programmatically

I added some UIBarButtonItems to a navigationBar in interface builder. Then I change the buttons (remove,change title or add removed buttons) programatically, and the button indents something like 15 pixels inwards (away from the left/right border of the navigationbar). After the view is reloaded the buttons are back in their original place.
An example is the edit button at the top of a table view: it moves a little bit inward after i change it from edit to done. When I switch it from done back to edit, it stays in the same awkward position.
Can anyone tell me how this comes, and especially what I should do to prevent it?

Resources