How to make a UITableViewController subclass respect topLayoutGuide in iOS7? - ios

in my app I have a simple UITableViewController that's just plain Objective-C code, no .xib or storyboard involved. It represents the contents of one tab in a tab bar.
Since iOS 7 its contents are overlapped by the status bar at the top and tab bar at the bottom.
Using only code, how can I make the table view add space at the top and bottom to align with topLayoutGuide and bottomLayoutGuide?
I know about
self.edgesForExtendedLayout=UIRectEdgeNone;
but that seems to simply shrink the table view to not intersect the tab bar and to disable the transparency of the tab bar. Instead I'd like the table view to add some padding.
Thanks!
Update:
I've also tried explicitly setting automaticallyAdjustsScrollViewInsets to YES, but that didn't help either (should be the default behavior anyway).

It seems this is not (yet) supported, at least for programmatically created UITableViewControllers without an UINavigationController that's embedding them.
I checked the position for both layout guides, and at run-time both off-sets read 0 distance from the edges of the screen. Hence automaticallyAdjustsScrollViewInsets won't set the insets correctly.
So now I actually modify my first section header and last section footer manually to add 21 pixels at the top and 50 pixels at the bottom respectively.
Bummer. :-(

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.

How to place any view below any other view which is getting it's position from code

I've created 4 subviews of white color & a yellow one as you can see in reference image I've shared below.
And I've programmatically changed the position of Tabbar from bottom to top just below to navigation bar as you can see in below image (When it is running in the simulator).
Now since I've constraints for that yellow view in image as follow
It is appearing just below to navigation bar but I want it to be displayed just below the Tabbar.
Since Tabbar is getting its position programmatically & other views (including yellow view) are getting their positions from the storyboard.
And since storyboard UIelements are get settled before any other UIelement which are coming from the program or at least get their position from programmatically.
What could be the best way to achieve what I want.
Please refer my storyboard as well to get more understanding. (Refer Below image)
I also want to fit all 5 subviews in the space between tabbar & bottom of the screen. I want to calculate 1/5th of that space & assign this height to each subview. I'd later reduce few pixels to separate them.
Why not add the height of the tab bar to the yellow view's top position? That way, you'd set the constraint something like:
Fajar.top = top + 44
If the tab bar is always visible, then that should work. But of course, if the tab bar only appears at times, you'd probably have to change that constraint programmatically depending on the change ...

TopLayoutGuide spacing set to 0 creates empty space

I am creating UI in xcode. I have added imageView which topLayoutGuide vertical spacing is set to 0. So I think that it should be positioned right under status bar. However it is positioned under navigation bar (which is not even present).
In the same storyboard I have some views that are embed in navigation controller and it is set to transculent=NO. But this view isnt even linked to them. So I dont think that this should be a problem.
Any ideas how to fix this?
Thanks in advance

How to create space between UINavigationBar and top of UITableView

I have a UITableView in my storyboard. I put a navigation bar at the top of the view. However the title seems to close to the top of the view near the time and battery. Is there any way to create spacing like in the view to the left of that one? I tried simply dragging the navigation bar down but it seems pinned to the top of the view. Any help is appreciated. Thanks!
If you are using autolayout (which I very much recommend), you are just missing a Vertical Space Constraint between your container view and your table view.
See the size inspector (as shown below) for a list of constraints on a UI element, or browse your Document Outline for missing constraints.

Autolayout doesn't work?

So I'm creating my app in storyboard, and i'm using an navigation controller, added an add view, and trying to auto layout stuff there.
But the problem is, i only get blue guided lines when I'm near the corner left and right. So it's basically not looking at my Navigationbar above.. and just ignoring it.
Also, when I'm switching the simulator to a 3.5 inch (I'm making it in 4 inch) the buttons and labels will disappear underneath it. And they are added to Auto layout blue lines?
The blue lines are not AutoLayout, but just lines that guide you when placing your views. Auto Layout only comes in when you start adding constraints. Check out Apple's Autolayout guide:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/Introduction/Introduction.html
Control drag from the label to the navigation bar and it will show the below window. The first option is for you to create the constraint from the Navigation Bar bottom.
The Top Layout Guide is a iOS 7 specific feature which marks the bottom line of the navigation bar. The total height of the navigation bar (if present) plus the height of the status bar (if present) equals the toplayoutGuide.length

Resources