[英]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. 我有一个UITableViewController子类,想向表视图添加左右边缘空白。 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.
我不想通过将tableview作为子视图移动到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. 经过一些自我测试之后,我认为最好的选择是
customise
TableViewCells
并在其中添加margin
属性。 By doing so, you can easily change the margin dynamically
or set it to 0
if you want to remove it completely. 这样,您可以轻松地
dynamically
更改边距,或者如果要完全删除它,可以将其设置为0
。
For inspiration check out the answer to this post by @ezcoding . 为了获得灵感,请通过@ezcoding查看此帖子的答案 。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.