4

Helo guys i found How to create rounded UIButton with top-left & bottom-left corner radius only and its working. But problem is when button have some constrains it suddenly stop workin. Can anyone help me with that i tried change everything and still no results.

enter image description here

As you can see on picture its working for first orange Button in top of a picture but for TWITTER button its not working. Any help please ?

extension UIButton{
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
  }
}

and this is usage ( testBtn is that orange working button)

testBtn.roundCorners([.TopRight, .BottomRight], radius: 20)
    facebookBtn.roundCorners([.TopLeft, .BottomLeft], radius: 20)
    twitterBtn.roundCorners([.TopRight, .BottomRight], radius: 20)
Community
  • 1
  • 1
Mat The
  • 159
  • 11
  • 3
    Move testBtn.roundCorners([.TopRight, .BottomRight], radius: 20) facebookBtn.roundCorners([.TopLeft, .BottomLeft], radius: 20) twitterBtn.roundCorners([.TopRight, .BottomRight], radius: 20) to viewDidLayoutSubviews? – beyowulf Jan 12 '16 at 15:31
  • its working thank you very much. – Mat The Jan 13 '16 at 12:28
  • 1
    whatever, for swift 3.0 see my answer: http://stackoverflow.com/a/40222533/2594699 – Nhat Dinh Oct 27 '16 at 03:55

0 Answers0