UITableView contentInset allows you to watch a table horizontally in addition to vertical

I create a UITableViewController in code and push it over the navigation stack. This table view is intended to simply show a simple list of text elements.

I need to add some content Change to the table view that I add in the init method of my UITableViewController

self.tableView.contentInset = UIEdgeInsetsMake(7.0f, 5.0f, 7.0f, 5.0f); 

However, when I load the table view, it seems that the left and right ContentInset actually stretched the width of my table view by 10. Now I see a small horizontal scrollable area. I don't need horizontal scrolling on my desk. If I delete the ContentInset code, my table view behaves explicitly, that is, it just provides vertical scrolling. How can I keep it this way, but with my content? I tried to reduce the value of contentSize.width by 10 in viewWillAppear, this did not affect.

This seems like a duplicate, but without an acceptable answer: UITableView ContentInsets scrolls the content horizontally

In the layout, I marked the desired ContentInset with a dashed line ---

enter image description here

Thanks.

+8
ios iphone uitableview uiscrollview
source share
4 answers

In the end, I installed only the top and bottom inserts. To achieve left and right insertion and appearance, I created a custom cell as wide as the screen. But the actual contents of the cell were limited to a slightly narrower subzone inside the user cell. Thus, there was free space left and right of the spy.

+4
source share

Perhaps you should set the bounces scrollView property to YES. And do not install ContentInset.

0
source share

It looks like you need to do 2 things:

  • Add a table view to the container view and make the frame table look thinner (add left and right borders).
  • Add contentInset for top and bottom only.
0
source share

Another way that might work is that instead of setting the tableView frame tableView you can set the frame for the contentView cell, something like this,

 - (void) layoutSubviews { [super layoutSubviews]; CGRect frame = self.contentView.frame; frame.size.width = frame.size.width * 0.9; //90% of total width frame.origin.x = self.center.x - (frame.size.width/2); //center the contentView self.contentView.frame = frame; } 

Using the above, you can add any left or right or left additions to the cell. and all sub-types will be added to the contentView , so there are no problems there.

happy coding ..!

0
source share

All Articles