How to set .topright to corner redius with higher value t inside TableView Cell in Swift 3

226 views Asked by At

I want to set different values to corner radius with shadow effect to UIView inside TableView Cell, like this:

 this image

My code is:

cell.headerView.round(corners: [.topRight], radius: 35)

extension UIView {
    func round(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
        self.layoutIfNeeded()       
    }
}

This is working in iPhone SE Simulator but not working iPhone 6S Simulator.

2

There are 2 answers

0
Deepak Deore On BEST ANSWER

Swift 4

myView.clipsToBounds = true
        myView.layer.cornerRadius = 20
        myView.layer.maskedCorners = [.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMinXMinYCorner]
0
PGDev On

I have used almost same implementation and it is working fine on both device as well as simulator.

extension UIView
{
    func roundCorners(corners: UIRectCorner, radius: CGFloat)
    {
        let bounds = self.bounds
        let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let maskLayer = CAShapeLayer()
        maskLayer.frame = bounds
        maskLayer.path = maskPath.cgPath
        self.layer.mask = maskLayer
    }
}

class CustomCell: UITableViewCell
{
    @IBOutlet weak var customView: UIView!

    override func awakeFromNib()
    {
        super.awakeFromNib()
        self.customView.layer.cornerRadius = 10.0
        self.customView.roundCorners(corners: [.topRight], radius: 35.0)
    }
}

Screenshot:

enter image description here