简体   繁体   English

向UITableView中的原型单元格添加边距

[英]Adding Margins to Prototype Cells in UITableView

How can I add top, bottom, left, and right margin spacings between each individual prototype cell in UITableView? 如何在UITableView的每个原型单元之间添加顶部,底部,左侧和右侧的边距? (storyboard) Seems there are different solutions for different versions of iOS and none for swift yet. (storyboard)似乎有不同的解决方案适用于不同版本的iOS,而没有一个适用于Swift。

Current Cell 当前单元格

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
    }

You can't set margins between cells, but you can make it look like there are margins by giving the cell a clear background color, and adding a subview (to which you would add any other subviews you need) that is inset from the edges of the cell by whatever margins you want. 您不能在单元格之间设置边距,但是可以通过为单元格提供清晰的背景色,并添加一个从边缘插入的子视图(您将在其中添加所需的任何其他子视图)来使其看起来像是有边距。您想要的任何边距。 Give this view a background color, and turn off the cell separators. 为该视图提供背景色,然后关闭单元格分隔符。 This can all be done in IB with no code if you choose. 如果您选择的话,这一切都可以在IB中完成而无需代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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