Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement