ios - 向 UITableView 中的 Section Header 添加填充

标签 ios swift uitableview header

我创建了这个部分标题标题,不幸的是我不知道如何在右侧添加一些填充。

screenshot

这是我的代码:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let title: UILabel = UILabel()
    title.text = "Days"
    title.backgroundColor = UIColor.lightGrayColor()
    title.textAlignment = NSTextAlignment.Right
    return title
}

最佳答案

你可以这样做:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let view = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    let label = UILabel(frame: CGRect(x: 15, y: 5, width: tableView.frame.width, height: 20))
    label.text = "Days"
    label.textAlignment = .right
    view.addSubview(label)
    return view
}

关于ios - 向 UITableView 中的 Section Header 添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36390670/

相关文章:

objective-c - 当应用程序被卸载时,我的 UIPasteboard 上的持久性仍然有效。为什么?

javascript - onclick 阻止在 Mobile Safari 上复制+粘贴?

ios - 从后台线程更新 UI 的最佳/最常见方式

ios - Swift 中的 Flurry 推送通知

ios - 展开 Segue,添加单元格后滚动到 UITableView 的底部

ios - Xcode 模拟器 TableView 是黑色的

ios - 从 iOS Address Book API 查找常用联系人

iphone - iOS 应用分发问题

swift - 在 Swift 语言的日期选择器中自动选择日期

ios - 使用自定义单元格类时出现 Tableview 错误