From c0e182452fd1c7be96ef62b5f2016904ce29676e Mon Sep 17 00:00:00 2001 From: Sai Kambampati Date: Thu, 5 Oct 2017 11:37:27 -0700 Subject: [PATCH 1/3] Added Haptic Feedback when Button is pressed on --- Source/ButtonProgressBar.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/ButtonProgressBar.swift b/Source/ButtonProgressBar.swift index ebf5885..4fc8500 100644 --- a/Source/ButtonProgressBar.swift +++ b/Source/ButtonProgressBar.swift @@ -220,6 +220,9 @@ public class ButtonProgressBar: UIButton { override public func touchesBegan(_ touches: Set, with event: UIEvent?) { super.touchesBegan(touches, with: event) + let generator = UIImpactFeedbackGenerator(style: .light) + generator.impactOccurred() + AudioServicesPlaySystemSound(1519) UIView.animate(withDuration: 0.05) { self.titleLabel!.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) self.alpha = 0.85 From 00e05dfbaeb2b3d202ea46f4d6109a1f59fc8621 Mon Sep 17 00:00:00 2001 From: Sai Kambampati Date: Thu, 5 Oct 2017 11:41:50 -0700 Subject: [PATCH 2/3] Update ButtonProgressBar.swift --- Source/ButtonProgressBar.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/ButtonProgressBar.swift b/Source/ButtonProgressBar.swift index 4fc8500..2a7d554 100644 --- a/Source/ButtonProgressBar.swift +++ b/Source/ButtonProgressBar.swift @@ -21,6 +21,7 @@ THE SOFTWARE. */ import UIKit +import AudioToolbox public class ButtonProgressBar: UIButton { From c51eacc381670973add5d459a00815a2e3fe42b2 Mon Sep 17 00:00:00 2001 From: Sai Kambampati Date: Thu, 5 Oct 2017 12:56:09 -0700 Subject: [PATCH 3/3] Create hapticEnabled variable for users to customize --- Source/ButtonProgressBar.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/ButtonProgressBar.swift b/Source/ButtonProgressBar.swift index 2a7d554..d2d0bdf 100644 --- a/Source/ButtonProgressBar.swift +++ b/Source/ButtonProgressBar.swift @@ -26,6 +26,7 @@ import AudioToolbox public class ButtonProgressBar: UIButton { private var cornerRadius: CGFloat = 5 + private var hapticEnabled: Bool = false public private(set) var progress: CGFloat = 0.0 var indeterminate: Bool = false @@ -221,9 +222,15 @@ public class ButtonProgressBar: UIButton { override public func touchesBegan(_ touches: Set, with event: UIEvent?) { super.touchesBegan(touches, with: event) - let generator = UIImpactFeedbackGenerator(style: .light) + if #available(iOS 10.0, *) { + if hapticEnabled != false { + let generator = UIImpactFeedbackGenerator(style: .light) generator.impactOccurred() AudioServicesPlaySystemSound(1519) + } else { + return + } + } UIView.animate(withDuration: 0.05) { self.titleLabel!.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) self.alpha = 0.85