change width of tableviewcell swift

前端 未结 2 1811
自闭症患者
自闭症患者 2021-01-01 06:10

I have a tableView using IB with custom cells and prototype cells.

I\'m trying to make the cells a little shorter in width than the tableView.frame to leave a little

2条回答
  •  庸人自扰
    2021-01-01 06:58

    The cells in the tableview are supposed to be as wide as their container.

    If you need your cells to have a different width than the table view, I would suggest adding a view as subview to cell.contentView and make that view as wide as you need while making sure the contentView has clear background and no separator and all (so that it appears it is not there).

    Another solution would be to have the tableView not as wide as it's superview by adding the left/right padding to it. But the you would have the issue that on the left and right side, where the padding is, you won't be able to scroll the tableView

    I consider the cleanest solution to use a collectionView. It is not that much different than a tableView and you can configure the entire size of the cell, not just the height.

    Hope this helps you fix your problem. Let me know if you need more help.

提交回复
热议问题