如何在UITableView中的每个原型单元格之间添加顶部,底部,左侧和右侧边距? (故事板)似乎对于不同版本的iOS有不同的解决方案,对于swift来说似乎没有。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("OptionCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = self.options[indexPath.row]
cell.textLabel?.textAlignment = NSTextAlignment.Center
cell.layer.cornerRadius = 5.0;
cell.layer.borderColor = UIColor.whiteColor().CGColor
cell.layer.borderWidth = 1.5
cell.backgroundColor = UIColor.clearColor()
return cell
}
答案 0 :(得分:4)
您无法在单元格之间设置边距,但是您可以通过为单元格提供清晰的背景颜色并添加子视图(您可以向其添加所需的任何其他子视图)使其看起来像边距一样从你想要的任何边距插入单元格的边缘。为此视图提供背景颜色,然后关闭单元格分隔符。如果您愿意,这可以在IB中完成,无需代码。