-
Notifications
You must be signed in to change notification settings - Fork 1
/
LiveView.swift
40 lines (30 loc) · 1.42 KB
/
LiveView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import UIKit
import PlaygroundSupport
public func showOutput(_ image: UIImage) {
let liveView = PreviewViewController()
let drawRect = CGRect(x: 0, y: 0, width: 1000, height: 1000)
liveView.drawPreview { ctx in
let innerRenderer = UIGraphicsImageRenderer(bounds: drawRect)
let innerImage = innerRenderer.image { ctx in
UIColor.red.setFill()
UIColor.black.setStroke()
ctx.cgContext.setLineWidth(40)
let bigCircle = CGRect(x: 300, y: 300, width: 400, height: 400)
ctx.cgContext.addEllipse(in: bigCircle)
ctx.cgContext.drawPath(using: .fillStroke)
ctx.cgContext.setLineWidth(10)
let leftCircle = CGRect(x: 100, y: 400, width: 200, height: 200)
ctx.cgContext.addEllipse(in: leftCircle)
let rightCircle = CGRect(x: 700, y: 400, width: 200, height: 200)
ctx.cgContext.addEllipse(in: rightCircle)
let topCircle = CGRect(x: 400, y: 100, width: 200, height: 200)
ctx.cgContext.addEllipse(in: topCircle)
let bottomCircle = CGRect(x: 400, y: 700, width: 200, height: 200)
ctx.cgContext.addEllipse(in: bottomCircle)
ctx.cgContext.drawPath(using: .fillStroke)
}
innerImage.draw(in: drawRect, blendMode: .normal, alpha: 0.2)
}
liveView.readerImageView.image = image
PlaygroundPage.current.liveView = liveView
}