Add padding to Section Header in UITableView

后端 未结 2 1256
心在旅途
心在旅途 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: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
    }
    

提交回复
热议问题