简体   繁体   中英

Adding left and right margins to a table view inside UITableViewController

I am having a UITableViewController subclass and want to add left and right edge margins to the tableview. I tried below but that is not helping. I do not want to change the view hierarchy by moving tableview as subview to a UIView.

self.tableView.contentInset = UIEdgeInsetsMake(0.0, 20.0, 0.0, 20.0)

What can be done in this case?

After some testing myself I think your best options is to customise your TableViewCells and add a margin property there. By doing so, you can easily change the margin dynamically or set it to 0 if you want to remove it completely.

For inspiration check out the answer to this post by @ezcoding . Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM