gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:24:59 40 4
gpt4 key购买 nike

如何在 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/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com