From 5e224cf89f9d9ec7d9453a32b31664bfa6405834 Mon Sep 17 00:00:00 2001 From: Ivan Koshkin Date: Wed, 15 Nov 2017 21:42:42 +0100 Subject: [PATCH 1/3] update for swift 4 --- DottedLineView/Classes/DottedLineView.swift | 38 ++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/DottedLineView/Classes/DottedLineView.swift b/DottedLineView/Classes/DottedLineView.swift index dcce725..4b86391 100644 --- a/DottedLineView/Classes/DottedLineView.swift +++ b/DottedLineView/Classes/DottedLineView.swift @@ -12,7 +12,7 @@ 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) @@ -37,15 +37,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 +55,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] 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 } } From 6cb0d9078ada3baa8636411178f0391325b8900c Mon Sep 17 00:00:00 2001 From: Ivan Koshkin Date: Wed, 15 Nov 2017 21:43:08 +0100 Subject: [PATCH 2/3] vars to to change dash length --- DottedLineView/Classes/DottedLineView.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/DottedLineView/Classes/DottedLineView.swift b/DottedLineView/Classes/DottedLineView.swift index 4b86391..a54f421 100644 --- a/DottedLineView/Classes/DottedLineView.swift +++ b/DottedLineView/Classes/DottedLineView.swift @@ -16,7 +16,13 @@ public class DottedLineView: UIView { @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 @@ -77,7 +83,7 @@ public class DottedLineView: UIView { 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 } From 84fb9604970186e9056cddb6a899cf7277264cf4 Mon Sep 17 00:00:00 2001 From: Ivan Koshkin Date: Wed, 15 Nov 2017 21:43:17 +0100 Subject: [PATCH 3/3] pod version change --- DottedLineView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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