我有一个tableView使用IB与自定义单元格和原型单元格.
我正在尝试使单元格的宽度比tableView.frame略短,以在左右角之间留出一点空间.
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell
cell.bounds = CGRectMake(10, self.tableView.frame.origin.y, 30, self.tableView.frame.size.height)
cell.layer.bounds = CGRectMake(10, self.tableView.frame.origin.y, 30, self.tableView.frame.size.height)
cell.textLabel?.bounds = CGRectMake(10, self.tableView.frame.origin.y, 30, self.tableView.frame.size.height)
Run Code Online (Sandbox Code Playgroud)
更新:这是一个很好的示例,解释如何将subView添加到tableView. http://natashatherobot.com/ios-frame-vs-bounds-resize-basic-uitableview-cell/
更新2:看起来没有一种简单的方法可以做到这一点.据我所知,有3种方法可以达到这个目的: