IHVerticalDashLine.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // IHVerticalDashLine.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/1/15.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class IHVerticalDashLine: UIView {
  10. private var lineLength : CGFloat?
  11. private var lineSpacing : CGFloat?
  12. private var viewHeight : CGFloat?
  13. private var lineColor : UIColor?
  14. init(frame : CGRect,lineLength:CGFloat,lineSpacing:CGFloat,lineColor:UIColor) {
  15. super.init(frame: frame)
  16. self.backgroundColor = .clear
  17. self.lineSpacing = lineSpacing
  18. self.lineLength = lineLength
  19. self.lineColor = lineColor
  20. self.viewHeight = frame.size.height
  21. }
  22. required init?(coder: NSCoder) {
  23. fatalError("init(coder:) has not been implemented")
  24. }
  25. override func draw(_ rect: CGRect) {
  26. let context = UIGraphicsGetCurrentContext()
  27. context?.beginPath()
  28. context?.setLineWidth(1)
  29. context?.setStrokeColor(lineColor!.cgColor)
  30. let lengths = [lineLength!,lineSpacing!]
  31. context?.setLineDash(phase: 0, lengths: lengths)
  32. context?.move(to: CGPoint(x: 0, y: 0))
  33. context?.addLine(to: CGPoint(x: 0, y: viewHeight!))
  34. context?.strokePath()
  35. context?.closePath()
  36. }
  37. }