我已经设计了标题文本的样式:
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
。有什么方法可以添加一些顶部/底部边距/填充吗?
titleForHeaderInSection
方法将具有默认的节标题框架。您可以使用viewForHeaderInSection
方法来定制它。试试这个代码:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerFrame = tableView.frame
let title = UILabel()
title.frame = CGRectMake(10, 10, headerFrame.size.width-20, 20) //width equals to parent view with 10 left and right margin
title.font = title.font.fontWithSize(14)
title.text = self.tableView(tableView, titleForHeaderInSection: section) //This will take title of section from 'titleForHeaderInSection' method or you can write directly
title.textColor = UIColor.blueColor()
let headerView:UIView = UIView(frame: CGRectMake(0, 0, headerFrame.size.width, headerFrame.size.height))
headerView.addSubview(title)
return headerView
}
希望这对你有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)