diff --git a/DottedLineView.podspec b/DottedLineView.podspec index cef5e4b..2989086 100644 --- a/DottedLineView.podspec +++ b/DottedLineView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'DottedLineView' - s.version = '1.0.0' + s.version = '1.0.1' s.summary = 'Draw horizontal or vertical dotted line for iOS.' s.description = <<-DESC diff --git a/DottedLineView/Classes/DottedLineView.swift b/DottedLineView/Classes/DottedLineView.swift index dcce725..a54f421 100644 --- a/DottedLineView/Classes/DottedLineView.swift +++ b/DottedLineView/Classes/DottedLineView.swift @@ -12,11 +12,17 @@ import UIKit public class DottedLineView: UIView { @IBInspectable - public var lineColor: UIColor = UIColor.blackColor() + public var lineColor: UIColor = UIColor.black @IBInspectable public var lineWidth: CGFloat = CGFloat(4) - + + @IBInspectable + public var dashStroke: CGFloat = CGFloat(4) + + @IBInspectable + public var dashSkip: CGFloat = CGFloat(4) + @IBInspectable public var round: Bool = false @@ -37,15 +43,15 @@ public class DottedLineView: UIView { initBackgroundColor() } - override public func drawRect(rect: CGRect) { + override public func draw(_ rect: CGRect) { let path = UIBezierPath() path.lineWidth = lineWidth if round { - configureRoundPath(path, rect: rect) + configureRoundPath(path: path, rect: rect) } else { - configurePath(path, rect: rect) + configurePath(path: path, rect: rect) } lineColor.setStroke() @@ -55,54 +61,54 @@ public class DottedLineView: UIView { func initBackgroundColor() { if backgroundColor == nil { - backgroundColor = UIColor.clearColor() + backgroundColor = UIColor.clear } } private func configurePath(path: UIBezierPath, rect: CGRect) { if horizontal { let center = rect.height * 0.5 - let drawWidth = rect.size.width - (rect.size.width % (lineWidth * 2)) + lineWidth + let drawWidth = rect.size.width - (rect.size.width.truncatingRemainder(dividingBy: lineWidth * 2)) + lineWidth let startPositionX = (rect.size.width - drawWidth) * 0.5 + lineWidth - path.moveToPoint(CGPoint(x: startPositionX, y: center)) - path.addLineToPoint(CGPoint(x: drawWidth, y: center)) + path.move(to: CGPoint(x: startPositionX, y: center)) + path.addLine(to: CGPoint(x: drawWidth, y: center)) } else { let center = rect.width * 0.5 - let drawHeight = rect.size.height - (rect.size.height % (lineWidth * 2)) + lineWidth + let drawHeight = rect.size.height - (rect.size.height.truncatingRemainder(dividingBy: lineWidth * 2)) + lineWidth let startPositionY = (rect.size.height - drawHeight) * 0.5 + lineWidth - path.moveToPoint(CGPoint(x: center, y: startPositionY)) - path.addLineToPoint(CGPoint(x: center, y: drawHeight)) + path.move(to: CGPoint(x: center, y: startPositionY)) + path.addLine(to: CGPoint(x: center, y: drawHeight)) } - let dashes: [CGFloat] = [lineWidth, lineWidth] + let dashes: [CGFloat] = [dashStroke, dashSkip] path.setLineDash(dashes, count: dashes.count, phase: 0) - path.lineCapStyle = CGLineCap.Butt + path.lineCapStyle = CGLineCap.butt } private func configureRoundPath(path: UIBezierPath, rect: CGRect) { if horizontal { let center = rect.height * 0.5 - let drawWidth = rect.size.width - (rect.size.width % (lineWidth * 2)) + let drawWidth = rect.size.width - (rect.size.width.truncatingRemainder(dividingBy: lineWidth * 2)) let startPositionX = (rect.size.width - drawWidth) * 0.5 + lineWidth - path.moveToPoint(CGPoint(x: startPositionX, y: center)) - path.addLineToPoint(CGPoint(x: drawWidth, y: center)) + path.move(to: CGPoint(x: startPositionX, y: center)) + path.addLine(to: CGPoint(x: drawWidth, y: center)) } else { let center = rect.width * 0.5 - let drawHeight = rect.size.height - (rect.size.height % (lineWidth * 2)) + let drawHeight = rect.size.height - (rect.size.height.truncatingRemainder(dividingBy: lineWidth * 2)) let startPositionY = (rect.size.height - drawHeight) * 0.5 + lineWidth - path.moveToPoint(CGPoint(x: center, y: startPositionY)) - path.addLineToPoint(CGPoint(x: center, y: drawHeight)) + path.move(to: CGPoint(x: center, y: startPositionY)) + path.addLine(to: CGPoint(x: center, y: drawHeight)) } let dashes: [CGFloat] = [0, lineWidth * 2] path.setLineDash(dashes, count: dashes.count, phase: 0) - path.lineCapStyle = CGLineCap.Round + path.lineCapStyle = CGLineCap.round } }