0

I used this extension to round two top corner of a table view.

self.tableView.roundCorners([.TopLeft, .TopRight], radius: 8)



extension UIView {
    func roundCorners(corners:UIRectCorner, radius: CGFloat) {
        let rect = self.layer.bounds
        let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.frame = rect
        mask.path = path.CGPath
        self.layer.masksToBounds = true
        self.layer.addSublayer(mask)

        self.layer.mask = mask
    }
}

When I run the app the table view is always clipped off some of the bottom rows, but when I comment out the round corner line, the table worked perfectly fine. Anyone know why this is happen?

Side notes: if I set the cornerRadius for the table view then it works fine, but it round all four of the corner and I only want it round two top corner.

JozackOverFlow
  • 267
  • 4
  • 19
  • Also http://stackoverflow.com/q/36092304/77567 – rob mayoff Aug 27 '16 at 03:53
  • @robmayoff hi Rob, thanks for your link, I tried but did not work for table view, when table scroll down the content is still clipped off. So it's not a duplicate. – JozackOverFlow Aug 27 '16 at 04:19
  • It's the same problem: your mask doesn't match the bounds of your table view. The table view scrolls by changing the origin of its `bounds`, so you need to either reset the mask path every time the table view scrolls, or you need to put the mask on the table view's superview. – rob mayoff Aug 27 '16 at 05:26

0 Answers0