As you can see from the video, when the code is built and ran, the Red View is 0px from the top edge. But after scrolling down and tapping the status bar to return to the top, there is a gap between the top of the screen and Red View (i.e. the black area).
GIF of Simulator
What can I do to resolve the issue if the intended behaviour is for the Red View to be 0px from the top of display when the user scroll up to the very top?
Try setting a minus value for the scrollviews content inset:
scrollView.contentInset = UIEdgeInsets(top: -40, left: 0, bottom: 0, right: 0)
Your could also check the safe area.
This is a normal behavior in iOS. iOS will try to leave room for the status bar if you are using safe areas.
Related
What's the proper way to set left an right margins for a tableviewcell within a tableview?
Here's an image of what Im going for:
And here's what I actually have:
I can get the spacing on the left, but not on the right. I've set the contentInsent to this:
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
but it's not working either. Instead it's allowing a horizontal scroll on the tableview.
If I wanted to achieve the interface you're showing, this would have nothing to do with the table view insets. I would draw the cells to have that appearance. This would be a matter of the cell's background view. Each cell would fill the space, as intended, but the cell would draw an inner rounded rect within itself.
What is the magical incantation for adjusting a UITableView's height when the keyboard is shown on-screen FOR ALL DEVICES? In the keyboardDidShow notification, I'm doing
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height - view.safeAreaInsets.bottom, right: 0)
tableView.scrollIndicatorInsets = tableView.contentInset
where the bottom constraint of my table view is Align Bottom to: Safe Area.
This works perfectly on all iPhone 5|6|7|8-type devices, but NOT on iPhone X* devices; the adjustment is not of a sufficient amount so as to move the bottom of the table up to meet the top of the keyboard. It's like ~58 pixels short.
Surely there must be some way to get this to work universally, eh? What am I missing?
This happens because iphones except iPhone X have no bottom safe area .
Try removing the view.safeAreaInsets.bottom.
I have a UITableView where the last cell is cut off behind the UITabBarController. I set the bottom constraint of the tableView to the top of my bottomLayoutGuide. I also tried this approach without success.
The only solution that worked was adding insets to the content (one point was enough):
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 1, right: 0)
Therefore I wonder if that's a normal behaviour or a scroll view bug.
I have subclassed UINavigationBar and customised the height of navigation-bar. Now it has 108pt height. But in all the screens, I am having the top area of tableview/scrollview behind the custom navigation-bar. I have tried extend edges under top bar, but it only move 64pt.
Is there any way to move all the contents below the custom navigation bar, without modifying top constraint or setting content insets of every screen?
Did you try -
automaticallyadjustsscrollviewinsets = false
This can be done from storyboard as well as from code.
Also, try setting your navigation bar to opaque.
Hope this helps.
First of all i would avoid to change the height of the apple navigationBar. This can cause some more problems. As you can see.
Anyway you could change the contentInset of the tableView.
tableView.contentInset = UIEdgeInsets(top: HEIGHTOFNAVIGATIONBAR - ADDEDHEIGHT, left: 0, bottom: 0, right: 0)
I'd like to have a UITableView which is full screen. But the content of the UITableView should have a padding on the left and right.
So I tried to set ContentInset. But now the cells are as wide as the UITableView and the UITableView scrolls horizontally.
Is there a way to say that the UITableView content's width should become narrowed by the horizontal content insets? Or do I have to add the padding to all cells and header/footer views?
I don't want to narrow the table view itself, because the scroll indicator should stay at the right side of the screen and not in the middle.
The here (How to set the width of a cell in a UITableView in grouped style) suggested solution seems to be not as generic as i'd love to, beacuse the cells and header and footer views have to know about the padding (at least 3 places to maintain instead of one)
I don't want to narrow the table view itself, because the scroll
indicator should stay at the right side of the screen and not in the
middle.
This makes you happy?
_tableView.clipsToBounds = NO;
_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -30.f);
If you don't like clipsToBounds = NO effects, you can embed the tableView in container view which is clipsToBounds = YES.
Set the layout margins of the table view. For this to work make sure your constraints in the cells are set relative to the superview margin.
tableView.layoutMargins = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40)