nirav
nirav

Reputation: 651

Bottom Corners are not working in swift

I try to set topright & bottomRight corner as follow but it is not working

Try 1

let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: self.main_scroll.bounds,
                                    byRoundingCorners: [.TopRight, .BottomRight],
                                    cornerRadii: CGSize(width: 10.0, height: 10.0)).CGPath
self.main_scroll.layer.mask = maskLayer

Try 2

let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: self.main_scroll.frame, byRoundingCorners: UIRectCorner.BottomRight.union(.TopRight), cornerRadii: CGSizeMake(100, 100)).CGPath
self.main_scroll.layer.mask = maskLayer

Try 3

let rectShape = CAShapeLayer()
rectShape.bounds = self.main_scroll.frame
rectShape.position = self.main_scroll.center
rectShape.path = UIBezierPath(roundedRect: self.main_scroll.bounds, byRoundingCorners: [.BottomRight,.TopRight], cornerRadii: CGSize(width: 500, height: 500)).CGPath
self.main_scroll.layer.mask = rectShape

Thank you,

Upvotes: 1

Views: 276

Answers (1)

jplara
jplara

Reputation: 21

Try this using DispatchQueue.main.async this works for me

     DispatchQueue.main.async {
        let path = UIBezierPath(roundedRect: self.messageLabel.bounds,
                                byRoundingCorners:[.bottomRight, .topRight, .topLeft],
                                cornerRadii: CGSize(width: 8, height:  8))
        let maskLayer = CAShapeLayer()
        maskLayer.path = path.cgPath
        self.messageLabel.layer.mask = maskLayer
    }

Upvotes: 2

Related Questions