Can I add a bottom padding to iOS UINavigationBar to alter the visual height of the bar? - ios

I’m implementing a design that requires the navigation bar to visually appear to be 64px tall (even though the content fits inside the standard height). The standard UINavigationBar height on iOS is 44px and it is strongly discouraged try to to change the that (see: https://developer.apple.com/forums/thread/88202?answerId=274620022#274620022).
So, what I’m trying to do instead is to add a padding of 10px both above and below the bar itself, but I can’t figure out if this is even possible.
I am able to extend the bar by 20px by setting the UINavigationController’s additionalSafeAreaInsets.top = 20, but the bottom of the navigation bar is still flush with the bottom of the navigation controller, and I need it to be -10px from bottom.
So, my question, is this possible, or am I chasing a ghost here?
EDIT: To clarify, I want it to look like how the navigation bar looks in the iMessage conversation view, i.e. a tall navigation bar, but with vertically centered content.

I think you should make a customized navigation bar to solve this issue.
Because built-in UI is not easier to adjust or customize. I have tried many tricks but they didn't work.
I already made a base screen that automatically adds a navigation bar on top, just need to set left/right button and the label. This navigation bar is just a normal UIView.

Related

UICollectionView under Navigation Bar, but not under Tab Bar

I have a UICollectionView that I want to go under the navigation bar. Basically I want it to ignore the entire top safe area, yet still want it to respect the bottom safe area, as there's a tabbar there. This is how it currently looks:
But I want the first cell to start directly the very top of the screen, under the (translucent) navigation bar and the status bar.
If I set collectionView.contentInsetAdjustmentBehavior = .never, then the top part works great, but then the bottom part of the collection view content is hidden by the tabbar - you can't scroll all the way to the bottom so to speak. So I have to manually add a bottom inset again? How do I get the height of the tabbar, including any bottom safe area on devices that have the home bar? Or is there a better way to tell the collectionview to ignore only the top area for its content inset adjustment?
You just need to set the bottom content inset of the collection view manually, after setting the adjustment behavior to .never.
The correct inset (including the tab bar and any home bar) can be found in safeAreaInsets.
collectionView.contentInsetAdjustmentBehavior = .never
collectionView.contentInset.bottom = collectionView.safeAreaInsets.bottom
You'll need to do this at a point when the safeAreaInsets have been set, such as viewDidLayoutSubviews.
As far as I remember, it used to be possible by simply adjusting the edgesForExtendedLayout property of the containing view controller, but that was phased out when safe areas were introduced in iOS 11 I believe.

Add a UINavigationBar to a UIView using Autolayout

I have a modal view that I'm presenting over the current view that has a UINavigationBar as a subview. Everything's working great, except that the UINavigationBar doesn't want to behave according to the autolayout constraints. Everything else in the view behaves as desired.
For some reason, the left and right bar button items are cut off on the edges of the view. I inspected the view at runtime to reveal that the total width of the UINavigationBar is the right width, but the bar buttons aren't conforming.
I also checked to make sure I didn't have negative margins or some other anomaly in the constraint definitions.
I have also tried setting the frame of the UINavigationBar manually, but it yielded no improvement.
Problematic View
Constraints
I'd like to keep the UINavigationBar, because it gets styled globally with the rest of my app (as opposed to creating a custom UIView imitation and styling it individually). Does anyone know what handle to jiggle to get the bar button items to conform to the right width?

Xcode uiscrollview shows up behind nav bar in IB

Trying to set up a scrollview in a UIViewController that has a nav bar. In IB my content gets pushed up to the top below the nav bar (see image).
When running the app on my phone the view is pushed down to sit below the nav bar which is fine. Is there anyway to get it to reflect like this in IB. It is hard to set up my content when half of it is cut off.
If I add a constraint to make the top of the view sit below the nav bar when I run the app it adds that offset and doesn't look correct. (I guess I could alter the constraint before running on my phone but seems like a ridiculous hack just to layout my app). (Already having major issues getting my scrollView to work the way I want it to... don't scroll if my content fits the screen but also use the scroll view to move the view up if the content is covered up by the keyboard but thats for another post)
when I run in simulator looks like this
In Interface Builder you should make sure your NavigationBar is set to Opaque in the simulated metrics. When you have a transparent Nav bar content can go underneath it.
It might look right in your app if you have a global attribute applied to make sure all nav bars are not translucent.

UIView bringSubviewToFront Breaks AutoLayout for UIScrollView

I have a rather simple screen where I am inserting a custom UINavigationBar at the top of the screen and a content area below it. I'm using AutoLayout and I'm visually declaring the relationship as so:
#"V:|-0-[_navBar(65)]-0-[_content]-0-|";
Now, this seems to work perfectly until I tried to have another view slide down from under the navigation bar. The nav bar contains a search field and I want the search results to slide down from under nav bar. As the code currently stands, the search results slide down on top of or in front of the nav bar and it looks quite strange. So I tried to push the nav bar to the top of the index stack using:
[self.view bringSubviewToFront:_navBar];
As far as the animation is concerned, it works perfectly. The search results no longer slide over the nav bar but they are in front of the content area. When the child of _content is a UIView it seems to be OK. However, when the child of _content is a UIScrollView, this seems to have introduced a 20px margin between the nav bar and the content area. Honestly, the space seems to be very close in size to the status bar although the nav bar has stayed the same height. I've tried bringing the nav bar to the front using many different techiniques but as soon as the nav bar and the content area are on different planes, it seems to break the autolayout constraint of 0px that is defined above.
Here is a sample project to show the bug. Look at the third item, "bringSubViewToFront bug".
Does anyone know what's going on?
The 20 point space seems like it would have something to do with the status bar, but I'm not sure why bringing the navigation bar to the front would apparently cause the scroll view to inset its content. Anyway, I was able to fix it by adding this line, after you bring the navigation bar to the front,
_scrollView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);

Creating custom implementation of navigation bar

I wish to create a view similar in behavior to the UINavigationBar.
I cannot simply customize the bar as I want the space to be taller and I want to have several other subviews on it other than just UIBarButtonItems. So, I want to be able to create a similar implementation including the floating/translucency effect.
I good example of this is the address bar in Safari in iOS 7. The UITextField on the bar is something that cannot be added on the default UINavigationBar. Nevertheless, the Safari bar still has the transparency.
I do not want it to shrink like it does in Safari when scrolling down, I simply want it to remain just like a UINavigationBar would. I was thinking about adding a subview to the root UIScrollView, but this would scroll along with everything. I want this to remain at the top, but I want other elements to be able to scroll.
How would I go about implementing this?
If you are confident that you can't to this with the default UINavigationBar, you could shrink (from the top) the UIScrollView with whatever the size the custom UINavigationBar is and then add the navbar as a subview to the root view at (0,0) coordinates. It will be independent from the scroll view.
On the other hand, if you need this to be persistent through the application and use it in all of the screens, it will be wise to make some changes starting for the AppDelegate, but that's for another question.
For the iOS 7 transparent-style part, look here: FXBlurView. Best of luck!

Resources