2

I want only the bottom border of my imageView to be rounded. How do I do that programmatically?

Thanks for your help!

Kegham K.
  • 1,589
  • 22
  • 40
Carl Henretti
  • 457
  • 2
  • 7
  • 17
  • You can do some workaround with BEZIER Paths – Mr. Xcoder May 21 '17 at 19:43
  • Possible duplicate of [Editing UIButton to have rounded corners on one side](http://stackoverflow.com/questions/43986812/editing-uibutton-to-have-rounded-corners-on-one-side) – JuicyFruit May 21 '17 at 19:56
  • Possible duplicate of [Round Top Corners of a UIButton in Swift](http://stackoverflow.com/questions/37163850/round-top-corners-of-a-uibutton-in-swift) – Robotic Cat May 21 '17 at 20:07

1 Answers1

5

You can do this by sub-classing UIImageView:

import UIKit
class CustomImageView: UIImageView {

override public func layoutSubviews() {
    super.layoutSubviews()
    self.roundUpCorners([.bottomLeft, .bottomRight], radius: 30)
}
}
extension UIView {
func roundUpCorners(_ 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
}
}

The result will be something like this:enter image description here

Ashik
  • 1,204
  • 12
  • 22