ios - 在 UITableView 中为原型(prototype)单元格添加边距

标签 ios objective-c uitableview swift

如何在 UITableView 中的每个原型(prototype)单元格之间添加顶部、底部、左侧和右侧边距间距? ( Storyboard)似乎针对不同版本的 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
    }

最佳答案

您不能在单元格之间设置边距,但是您可以通过为单元格提供清晰的背景颜色并添加一个嵌入的 subview (您可以向其添加任何其他您需要的 subview )来使其看起来像有边距从单元格的边缘按你想要的任何边距。给这个 View 一个背景颜色,并关闭单元格分隔符。如果您愿意,这一切都可以在 IB 中完成,无需代码。

关于ios - 在 UITableView 中为原型(prototype)单元格添加边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28522612/

相关文章:

ios - 如果一个文本字段已添加到单元格,如何不创建新的文本字段

iphone - 如何一起滚动一组 UIScrollView?

ios - 使用选定的 UIPicker 行作为自定义 UITableViewCell UILabel SWIFT 的文本

ios - 多点连接在后台断开

ios - 搜索结果不起作用去添加 tableviewcell

iphone - kABPersonImageFormatThumbnail 不拉图像

iphone - cocoa touch : NSDateComponents crashes on releasing a fresh instance

ios - 无法在 Swift 中获取最新的 CoreData DB 文件

ios - 更改导航栏ios6和ios7的颜色

iphone - 从应用程序内控制 iPhone 上的 iTunes