I’ve created a UIView with a semi-transparent black background to sit across my main app’s view. What I’m aiming for here is to create a cut-out circle shape so
Here is my conversion of the accepted answer in Swift:
public class OverlayView: UIView {
let fillColor: UIColor = UIColor.grayColor()
public var framesToCutOut: Array = [NSValue]()
override public func drawRect(rect: CGRect) {
super.drawRect(rect)
fillColor.setFill()
UIRectFill(rect)
if let context: CGContextRef = UIGraphicsGetCurrentContext() {
CGContextSetBlendMode(context, .DestinationOut)
for value in framesToCutOut {
let pathRect: CGRect = value.CGRectValue()
let path: UIBezierPath = UIBezierPath(ovalInRect: pathRect)
path.fill()
}
CGContextSetBlendMode(context, .Normal)
}
}