Define edge of a uiview by sides instead of the whole. Better to see to understand the question

0

Is it possible to put a border-radius of a uiview only on one side in swift ??

I have this:

I have selected the circular edges that I want to remove, but I do not know how to apply a border to some sides if and not others

My code for the image is this:

imagen!.layer.cornerRadius = 7.5
imagen!.clipsToBounds = true

My code for uiview the box:

vista!.layer.cornerRadius = 7.5
vista?.backgroundColor = AppDelegate().getColorCajas()
vista?.layer.borderColor = UIColor.grayColor().CGColor
vista?.layer.borderWidth = 1

EDITED

I added this code that is in @mhergon's response

let radius = 7.5
let pathDos = UIBezierPath(roundedRect: imagen!.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSize(width: radius, height: radius))
let maskDos = CAShapeLayer()
maskDos.path = pathDos.CGPath
imagen!.layer.mask = maskDos

But the images appear to me now cut, and the edge keeps coming out on the right side

    
asked by 05.09.2016 в 12:14
source

1 answer

0

Taking into account these parameters:

let view = UIView()
let radius = 3.0

You can do the following:

let path = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
view.layer.mask = mask

Logically you can change the corners you want to round up to your mind.

    
answered by 06.09.2016 / 17:14
source