I'm trying to make a rectangle mask with rounded corners which also would have a gradient (or inner shadow)
class RoundRectLayer : CALayer {
var rect : CGRect = .zero
override func draw(in ctx: CGContext) {
ctx.saveGState()
var path = CGPath(roundedRect: rect,
cornerWidth: rect.size.width / 10,
cornerHeight: rect.size.height / 10,
transform: nil)
ctx.addPath(path)
ctx.setFillColor(UIColor.clear.cgColor)
ctx.fillPath()
path = path.copy(strokingWithWidth: 4.0,
lineCap: CGLineCap.butt,
lineJoin: CGLineJoin.bevel,
miterLimit: 0)
ctx.addPath(path)
let colors = [
UIColor.yellow.cgColor,
UIColor.red.cgColor
]
ctx.fillPath()
ctx.restoreGState()
}
}
This is where I got so far, just a rounded rect. Radial and Linear gradients seem to be not the ones I expected.
Picture for reference (just a clear color instead of a white in the middle)
EDIT:
Okay, so I'm still having trouble with it. ACInnerShadowLayer from Inner shadow effect on UIView layer? got the effect I want, just there's a small issue. I would also like to have the same color background as that shadows. And now I only have that square in the middle and clear background