【发布时间】:2016-05-23 03:55:03
【问题描述】:
我已经设置了标题文本的样式:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? TableViewCell
cell!.titleLabel!.text = sections[indexPath.section].objects[indexPath.row].name
cell!.datetimeLabel!.text = "on " + sections[indexPath.section].objects[indexPath.row].date
return cell!
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 100
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section].heading // Open Events
}
我想在表格单元格部分开始之前在其下方添加一些边距/填充。我用heightForHeaderInSection 添加了一些边距/填充顶部。有什么方法可以添加一些顶部/底部边距/填充?
【问题讨论】:
-
你能不能不让标题高度更大,把“开放事件”标签上移?
-
将 heightForHeaderInSection 设为 120 并尝试。
-
@Fonix "open events" 不是标签,而是我刚刚在代码中添加的函数
tableView(tableView: UITableView, titleForHeaderInSection section: Int)中设置的部分标题 -
@Signare 将其设置为 120 只会增加顶部间距,而没有任何底部间距
-
创建一个标签并将其添加到单元格中。因此您可以设置该标签的顶部间距。
标签: ios swift uitableview