SHARE
TWEET

Untitled

a guest Jun 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2. import PlaygroundSupport
  3.  
  4. class CustomView: UIView {
  5.  
  6.     override init(frame: CGRect) {
  7.         super.init(frame: frame)
  8.  
  9.         backgroundColor = UIColor.green
  10.     }
  11.  
  12.     required init?(coder aDecoder: NSCoder) {
  13.         fatalError("init(coder:) has not been implemented")
  14.     }
  15.  
  16.     override func draw(_ rect: CGRect) {
  17.         super.draw(rect)
  18.  
  19.         let bottomRect = CGRect(
  20.             origin: CGPoint(x: rect.origin.x, y: rect.height / 2),
  21.             size: CGSize(width: rect.size.width, height: rect.size.height / 2)
  22.         )
  23.         UIColor.red.set()
  24.         guard let context = UIGraphicsGetCurrentContext() else { return }
  25.         context.fill(bottomRect)
  26.     }
  27. }
  28.  
  29. let view = CustomView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
  30. PlaygroundPage.current.liveView = view
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top