From 77c11cf049bf5940b4fc1a276d3d5cb5f2543195 Mon Sep 17 00:00:00 2001 From: Mijin Jeon Date: Sun, 21 Jul 2019 18:42:52 +0900 Subject: [PATCH] Feat: Implememt TickMarkSlider #89 Custom UISlider --- .../MartHoliday/View/TickMarkSlider.swift | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 MartHoliday/MartHoliday/View/TickMarkSlider.swift diff --git a/MartHoliday/MartHoliday/View/TickMarkSlider.swift b/MartHoliday/MartHoliday/View/TickMarkSlider.swift new file mode 100644 index 0000000..e2faca8 --- /dev/null +++ b/MartHoliday/MartHoliday/View/TickMarkSlider.swift @@ -0,0 +1,65 @@ +// +// TickMarkSlider.swift +// MartHoliday +// +// Created by YOUTH2 on 21/07/2019. +// Copyright © 2019 JINiOS. All rights reserved. +// + +import UIKit + +class TickMarkSlider: UISlider { + + var numberOfTickMarks: Float? + var unit: Float? + + let hapticGenerator = UIImpactFeedbackGenerator(style: .light) + + convenience init(tick: Float, maximumValue: Float, frame: CGRect) { + self.init(frame: frame) + self.numberOfTickMarks = tick + self.maximumValue = maximumValue + self.unit = (maximumValue - self.minimumValue) / tick + } + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + func addTickMarks() { + let width: CGFloat = 2.0 + let height: CGFloat = 15.0 + let yPosition: CGFloat = (self.frame.size.height - 13)/2 + var xPosition: CGFloat = 0 + + guard let numberOfTickMarks = self.numberOfTickMarks else { return } + let ratio = Float(self.frame.width) / numberOfTickMarks + + for i in 0..