Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义tableview标题的左上角和右上角_Ios_Swift_Uitableview - Fatal编程技术网

Ios 自定义tableview标题的左上角和右上角

Ios 自定义tableview标题的左上角和右上角,ios,swift,uitableview,Ios,Swift,Uitableview,我想以编程方式将圆角添加到tableview标题的左上角和右上角 您可以通过实现willDisplayHeaderView功能来实现: func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { let headerView = view as! UITableViewHeaderFooterView

我想以编程方式将圆角添加到tableview标题的左上角和右上角


您可以通过实现willDisplayHeaderView功能来实现:

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
            let headerView = view as! UITableViewHeaderFooterView
            headerView.contentView.backgroundColor = UIColor.lightGray
            headerView.contentView.layer.cornerRadius = 20
            headerView.contentView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
}

尝试添加
扩展名

extension UIView {

    func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
        let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.path = path.cgPath
        self.layer.mask = mask
    }
}
使用:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header")
        let header = cell as! HeaderView

        header.contentView.roundCorners([.topLeft, .topRight], radius: 100)

        return cell
}