在UITableView中的Section Header中添加填充

Kev*_*wig 3 header uitableview ios swift

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

截图

这是我的代码:

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
}
Run Code Online (Sandbox Code Playgroud)

Mas*_*eni 7

你可以这样做:

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 = NSTextAlignment.Right
    view.addSubview(label)
    return view
}
Run Code Online (Sandbox Code Playgroud)