Add padding to Section Header in UITableView

后端 未结 2 1234
心在旅途
心在旅途 2021-01-06 17:50

I created this section header title and unfortunately I don\'t know how to add some padding on the right.

\"scr

相关标签:
2条回答
  • 2021-01-06 18:05

    I found that adjusting it in the storyboard does the trick. Click on the tableView and set the Separator Inset on Left and Right edges. Make sure to click on the tableView and not the cell.

    0 讨论(0)
  • 2021-01-06 18:26

    You can do something like this:

    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
    }
    
    0 讨论(0)
提交回复
热议问题