// // IHVerticalDashLine.swift // Inhealth // // Created by weclouds on 2020/1/15. // Copyright © 2020 weclouds. All rights reserved. // import UIKit class IHVerticalDashLine: UIView { private var lineLength : CGFloat? private var lineSpacing : CGFloat? private var viewHeight : CGFloat? private var lineColor : UIColor? init(frame : CGRect,lineLength:CGFloat,lineSpacing:CGFloat,lineColor:UIColor) { super.init(frame: frame) self.backgroundColor = .clear self.lineSpacing = lineSpacing self.lineLength = lineLength self.lineColor = lineColor self.viewHeight = frame.size.height } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { let context = UIGraphicsGetCurrentContext() context?.beginPath() context?.setLineWidth(1) context?.setStrokeColor(lineColor!.cgColor) let lengths = [lineLength!,lineSpacing!] context?.setLineDash(phase: 0, lengths: lengths) context?.move(to: CGPoint(x: 0, y: 0)) context?.addLine(to: CGPoint(x: 0, y: viewHeight!)) context?.strokePath() context?.closePath() } }