How to make rounded corners and sides in UIview programmatically like has youtube:
I know how to make rounded corner but have no idea how to make rounded sides. I need to do it programmatically (not just setting image mask previously designed)
You can create a UIBezierPath. If you want to just round the corners, you can use bezierPathWithRoundedRect. If you want something more sophisticated, like that YouTube logo, you would use moveToPoint and a series of addCurveToPoint or addQuadCurveToPoint.
You can play around with those control points to get the effect you're looking for. The key is that you want the the first control point to be in line with the second control point of the preceding arc.
In this example, I'm just creating a CAShapeLayer and adding it as a sublayer. Alternatively, you could take this CAShapeLayer and add it as a mask to the layer of some other view, too. The key is that you just need to create a UIBezierPath that draws the outline you want, and either just draw it, add it as a sublayer, or use it as a mask.
Rounding corners of any
UIView
must go through its layer. Paste this into a new Xcode Playground:You can create a
UIBezierPath
. If you want to just round the corners, you can usebezierPathWithRoundedRect
. If you want something more sophisticated, like that YouTube logo, you would usemoveToPoint
and a series ofaddCurveToPoint
oraddQuadCurveToPoint
.For example, this is a close approximation:
That was generated with:
You can play around with those control points to get the effect you're looking for. The key is that you want the the first control point to be in line with the second control point of the preceding arc.
In this example, I'm just creating a
CAShapeLayer
and adding it as a sublayer. Alternatively, you could take thisCAShapeLayer
and add it as amask
to thelayer
of some other view, too. The key is that you just need to create aUIBezierPath
that draws the outline you want, and either just draw it, add it as a sublayer, or use it as a mask.