Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import PlaygroundSupport
- class CustomView: UIView {
- override init(frame: CGRect) {
- super.init(frame: frame)
- backgroundColor = UIColor.green
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- override func draw(_ rect: CGRect) {
- super.draw(rect)
- let bottomRect = CGRect(
- origin: CGPoint(x: rect.origin.x, y: rect.height / 2),
- size: CGSize(width: rect.size.width, height: rect.size.height / 2)
- )
- UIColor.red.set()
- guard let context = UIGraphicsGetCurrentContext() else { return }
- context.fill(bottomRect)
- }
- }
- let view = CustomView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
- PlaygroundPage.current.liveView = view
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement