Gap above ContentView / not the same height as UIScrollview - xib - swift

Issue: gap above where contentView starts. Should be 0.
Despite setting the content view top bottom leading and trailing to 0, the content view has a gap at the top. I am using auto layout only.
Scrollview background is blue &
Content view is grey for easy viewing.
If I set the content view to equal heights as the scroll view, I get an error. And this doesn't seem like the right approach away. According to this setting equal height is optional:
Apple auto layout scrollview page
I do set equal widths.
Entire Screen:
Top of Scroll view:
Bottom of scroll view -> this is right - flush with bottom of scroll view (not sure if that matters)
Constraints:
Subview constraints:
Please help!! Also I am using xib files - not sure if that matters.
Thank you!

You'll notice that the gap is equal in height to the navigation bar.
The gap is there because by default iOS assumes that when using a translucent navigation bar, scroll views (and their subclasses like table views) begin at the top of the screen, behind the translucent navigation bar.
iOS then assumes you do not want your content hidden behind the translucent navigation bar, so it applies a top content inset to any scroll view, of height equal to the navigation bar height.
This behavior can be overridden in two ways:
Unmark Adjust Scroll View Insets on the view controller (see image below)
Make your navigation bar not translucent. If you're using a Storyboard, select the navigation controller that contains the affected view controller, and unmark the Translucent checkbox.

Related

Make UITableView ignore Safe Area

I have a TableView inside a ViewController.
I made the TableView stretch to the View SuperMargings (with constraints) and disabled all SafeArea Inset options but my TableView is still under the SafeArea when I run my project.
How can I make my TableView go full height on iPhones with notch?
If you have already pinned tableView to it's superview(not to safeArea) with constraints but tableView still respects safeArea there is property contentInsetAdjustmentBehavior in UIScrollView(UITableView is subclass of UIScrollView as we know) since iOS 11.
This property is UIScrollView.ContentInsetAdjustmentBehavior enum with 4 options.
You need to set .never to contentInsetAdjustmentBehavior.
What works with any view is to associate the bottom constraint of the table view to the bottom anchor of the root (or parent) view (instead of the SafeArea).
This can be done in the storyboard editor double clicking on the constraint in the right inspector and changing the first item anchor from SafeArea to Superview (or any wanted view).
You can then set the edge insets at will if needed (to avoid content remain partially hidden behind the rounded frame corners or the notch if applying the same procedure to the top anchor)

how to set height of UIScrollView properly

I have a View. Inside that view I have Scroll view. Inside that Scroll View I have Content View. I set constraint that content view height and width is equal to View's height and width. The problem is that I have Navigation bar above of my superview. So when I look at simulator on running time it gives me extra space of that navigation bar inside UIScrollview. So have can I adjust height of content view.
I want to create constratin like this . Content view height = superview height - 66. 66 is the height of navigation bar...
the better way is inside your main view put Navigation bar on top of the view and put your Scrollview below the Navigation bar and inside that ScrollView Put the Content View
and if you want to put Navigation bar under the Scrollview you should specify the top space constraint of Content View other wise it will give the same output

UIScrollView in iOS doesn't response scroll to top

I have two UIScrollViews, one is horizental, the other is like page on the horizontal view. I want to click the status bar and have the vertical scrollView scroll to the top, but it doesn't work.
I searched for some information that said I must set UIScrollView.scrollsToTop=NO, but it doesn't work. Could somebody tell me why?
The scroll view only scrolls to the top if there is a single scroll view present with the scrollsToTop property set to YES.
Make sure it's set to NO on your horizontal scroll view and all the child, vertical scroll views contained within. Then, using the horizontal scroll view's delegate, as one vertical scroll view leaves the visible area, toggle the property to NO and toggle the incoming vertical scroll view's property to YES.

how do I have the navigationItem.titleView to be behind left and right bar button item

Is it possible to have the titleView to be behind the left and right bar button item on a navigation bar? I've set my titleView to have a width of 320 and it covers the left and right bar button item. I wonder if there is a way to move it to the back?
In my experiments, it appears that the titleView is always drawn after (above) the left and right bar button items. You could try spelunking the view hierarchy and using sendSubviewToBack:, provided that the title view is ever made part of the navigation bar's hierarchy.
If you can render the effect you're trying to achieve into an image, you could set that as the backgroundImage of the navigation bar, but this may not be practical.
Remember that you'll likely need to account for interface rotation in any case, since the navigation bar height (on iPhone) goes from 44px in portrait to 32px in landscape).

Toolbar placement off with Interface Builder

I have a view xib that I'm manipulating through IB (for various reasons) and it will be launched as a modal view in code. I have a Toolbar at top and another one at bottom with some other UI elements in between. When I run the app, the placement of the top Toolbar isn't as I see it during the layout in IB.
In IB, the top Toolbar is placed at top below the status bar correctly and the next UI element (a label) appears below it. However, in the simulator, the top half of the Toolbar appears underneath the status bar and thus making it look cut off and there is a lot of space between the Toolbar and the label, which isn't reflected in the layout in IB.
For modal views, should the height of the view be different? If so, what does it need to be?
The view's height is set to default height value of 480.
Is the style of the status bar set to Translucent Black in IB? This causes the status bar to not consume any space and as a result "float" above the underlying Views.