How can I load a ViewController with the contentInset included on load?
[self.tableView setContentInset:UIEdgeInsetsMake(300, 0, 0, 0)];
Right now this includes an inset, but it's above the edge of the screen and I need to scroll up to see it.
Related
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 a grouped UITableView. I've implemented tableView(:titleForHeaderInSection:) and tableView(:titleForFooterInSection:). As I scroll a long table, I can see that the section headers and footers contain the expected data. When I get to the bottom of the table and I drag up to see the footer of the last section, it has the correct data, but when I release my finger, the footer scrolls back down past the bottom of the screen and out of view. The last cell of the last section is what appears at the bottom of the screen rather than the footer of the last section.
How to fix it?
There's the last section and its footer. My finger is still on the screen
When I release my finger, the final footer slides off the bottom of the screen.
You can fix scrolling content issue by considering one of the following methods.
Method 1: Natural way to fix your problem by setting up your tableView frame and its bottom constraint properly from your storyboard.
Updated:
Method 2: You can validate your tableView frame in viewDidLayoutSubviews or viewWillLayoutSubviews
override func viewDidLayoutSubviews() {
tableView.frame = CGRect(x: 0, y: 0, width: tableView.frame.width, height: tableView.frame.height - (tabBarController?.tabBar.frame.size.height)!)
}
Method 3: Setting up your tableView frame by adjusting scroll view insets.
override func viewDidLayoutSubviews() {
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: (tabBarController?.tabBar.frame.size.height)!, right: 0)
}
I think it's blocked by the tabbar.
If using storyborad, reset the constraint of your tableView.
If not, you need to set the frame of your tableView correctly.
I'm trying to display my UITableView's content under the status bar upon app launch (it can be achieved now by scrolling).
This is my current result:
But I'd like it to appear like this:
I've set these attributes for the UINavigationController
And I've tried to adjust the insets like so in viewDidLoad:
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
However, it doesn't display as desired.
Add the code in this method- -viewDidLayoutSubview()
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
set the tableView contentInsetAdjustmentBehavior property
tableView.contentInsetAdjustmentBehavior = .never
This is what worked for me.
tableView.contentInset = UIEdgeInsets(top: -UIApplication.shared.statusBarFrame.size.height, left: 0, bottom: 0, right: 0)
Sorry the question sounds a bit confusing. I have two buttons overlapping my table view at the bottom, so if the table view scrolls "normal" the last row is partially hidden by these buttons. That's why I want to allow scrolling the table like the height of one row further down, so the last row is on top of these two buttons. How can I achieve this?
Adjust the content insets of the table view.
For instance, if your buttons are 50 points in height and your table's frame is the full window, you could set your table to snap to the top of your buttons like this:
tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
Note: In iOS 7+ view controllers have a property automaticallyAdjustsScrollViewInsets that is set to YES by default. When this property is set to YES, the contentInsets you set manually may be overridden. Assuming you have a nav bar of some kind that you want to scroll under, you can set your top edge inset to the length of the topLayoutGuide.
Your final solution (put this in viewDidLoad):
self.automaticallyAdjustsScrollViewInsets = NO;
tableView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 50, 0);
As pointed out by others, deprecations have made this solution impossible, and if we use a section footer, this will display at the inset all the time. A much simpler solution would be to add a tableFooterView to allow the bottom cells to scroll past the buttons. Like so:
let bottomView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 83))
bottomView.backgroundColor = .clear
tableView.tableFooterView = bottomView
This will make it so the contents shift up.
If you want them to shift down you can change the insets accordingly.
func shiftScrollingUp() {
yourScrollView.contentInsetAdjustmentBehavior = .never
yourScrollView.contentInset = UIEdgeInsetsMake(0, 0, 150, 0)
}
AutomaticallyAdjustsScrollViewInsets is deprecated in ios 11.
Can I make visible scrollIndicator ouf or frame tableview by
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -5);
tableview add on main View, and View have backgroundColor with image, I have next situation
So can I make it without enlarge width of tableView. If not I think i can easy make with method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
But I want know, maybe it is very simple, but I don't know how to do it