【发布时间】:2021-06-02 10:29:05
【问题描述】:
我想在多个自定义单元格之间添加间距。我有多个包含单元格的部分。
我有一个 UITableView 的 ViewController 类,我在其中指定信息:
struct customCell {
let title: String
}
func configure() {
models.append(Section(title: "", options: [
customCell(title: "Sounds"){
},
}
我有一个不同的 UITableViewCell 类,我使用 layoutSubViews() 方法:
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0))
我在这个网站上看到了其他解决方案,他们通过使用 UIEdgeInsets 获得间距。
我尝试使用 layoutSubViews() 方法,但没有成功,它将单元格的内容向上推,而不是在单元格之间添加空格:
当我使用所有插图时:
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top:15, left: 15, bottom: 15, right: 15))
内容从四面八方向内推:
我做错了什么?
【问题讨论】:
-
您不能在单元格之间添加空格。但是您可以轻松地使其看起来就像单元格之间有空间一样。
标签: ios swift xcode uitableview