From 3e3c543fb0cde58e74cd648994e4a62b8669ddf0 Mon Sep 17 00:00:00 2001 From: Lorenzo Greco Date: Sat, 12 Aug 2017 15:09:01 +0200 Subject: [PATCH 1/5] Update Readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e35418b..7ed6c9e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![logo](media/header_btn.png) -[![build](https://travis-ci.org/loregr/LGButton.svg?branch=master)](https://travis-ci.org/loregr/LGButton) ![platform](https://img.shields.io/badge/platform-ios-blue.svg) [![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](./LICENSE.md) [![Version](https://img.shields.io/cocoapods/v/LGButton.svg?style=flat)](http://cocoadocs.org/docsets/LGButton) +[![build](https://travis-ci.org/loregr/LGButton.svg?branch=master)](https://travis-ci.org/loregr/LGButton) ![platform](https://img.shields.io/badge/platform-ios-blue.svg) [![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](./LICENSE.md) [![Version](https://img.shields.io/cocoapods/v/LGButton.svg?style=flat)](http://cocoadocs.org/docsets/LGButton) [![gitcheese.com](https://s3.amazonaws.com/gitcheese-ui-master/images/badge.svg)](https://www.gitcheese.com/donate/users/7204248/repos/94624954) A fully customisable subclass of the native `UIControl` which allows you to create beautiful buttons without writing any line of code. From 75a6bb614ac783350a654f8f23d7469efa9f410f Mon Sep 17 00:00:00 2001 From: Guy Umbright Date: Thu, 31 Aug 2017 20:04:56 -0500 Subject: [PATCH 2/5] Remove touch "flash" and make it work more like a UIButton (remains highlight while touch is down, remove highlight, ignore action if moved to far away) --- LGButton/Classes/LGButton.swift | 71 +++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index 2c854cb..3a61b9f 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -8,13 +8,35 @@ import UIKit import QuartzCore +let untouchedAlpha : CGFloat = 1.0 +let touchedAlpha :CGFloat = 0.7 +let touchDisableRadius : CGFloat = 100.0 + @IBDesignable public class LGButton: UIControl { let availableFontIcons = ["fa", "io", "oc", "ic", "ma", "ti", "mi"] var gradient : CAGradientLayer? + var touchAlpha : CGFloat = untouchedAlpha + { + didSet { + updateTouchAlpha() + } + } + + var pressed : Bool = false + { + didSet { + if !showTouchFeedback + { + return + } + touchAlpha = (pressed) ? touchedAlpha : untouchedAlpha + } + } + fileprivate var rootView : UIView! @IBOutlet fileprivate weak var titleLbl: UILabel! @IBOutlet fileprivate weak var mainStackView: UIStackView! @@ -589,16 +611,51 @@ public class LGButton: UIControl { // MARK: - Touches // MARK: - override public func touchesBegan(_ touches: Set, with event: UIEvent?) { - if showTouchFeedback { - alpha = 0.7 - UIView.animate(withDuration: 0.3) { - self.alpha = 1 + override public func touchesBegan(_ touches: Set, with event: UIEvent?) + { + pressed = true + } + + override public func touchesEnded(_ touches: Set, with event: UIEvent?) + { + let shouldSendActions = pressed + pressed = false + if shouldSendActions + { + sendActions(for: .touchUpInside) + } + } + + override public func touchesMoved(_ touches: Set, with event: UIEvent?) + { + if let touchLoc = touches.first?.location(in: self) + { + if (touchLoc.x < -touchDisableRadius || + touchLoc.y < -touchDisableRadius || + touchLoc.x > self.bounds.size.width + touchDisableRadius || + touchLoc.y > self.bounds.size.height + touchDisableRadius) + { + pressed = false + } + else if self.touchAlpha == 1.0 + { + pressed = true } } } - override public func touchesEnded(_ touches: Set, with event: UIEvent?) { - sendActions(for: .touchUpInside) + override public func touchesCancelled(_ touches: Set, with event: UIEvent?) + { + pressed = false + } + + func updateTouchAlpha() + { + if self.alpha != self.touchAlpha + { + UIView.animate(withDuration: 0.3) { + self.alpha = self.touchAlpha + } + } } } From 8568f2c4054f94dccace9c94b505e1979fa4673f Mon Sep 17 00:00:00 2001 From: Guy Umbright Date: Sun, 17 Sep 2017 15:48:26 -0500 Subject: [PATCH 3/5] change for pull request, reworked alpha values due to initialization issues --- LGButton/Classes/LGButton.swift | 76 +++++++++++++++------------------ 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index 3a61b9f..e7d77b3 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -8,34 +8,22 @@ import UIKit import QuartzCore -let untouchedAlpha : CGFloat = 1.0 -let touchedAlpha :CGFloat = 0.7 -let touchDisableRadius : CGFloat = 100.0 @IBDesignable public class LGButton: UIControl { + enum TouchAlphaValues : CGFloat + { + case touched = 0.7 + case untouched = 1.0 + } + + let touchDisableRadius : CGFloat = 100.0 + let availableFontIcons = ["fa", "io", "oc", "ic", "ma", "ti", "mi"] var gradient : CAGradientLayer? - var touchAlpha : CGFloat = untouchedAlpha - { - didSet { - updateTouchAlpha() - } - } - var pressed : Bool = false - { - didSet { - if !showTouchFeedback - { - return - } - - touchAlpha = (pressed) ? touchedAlpha : untouchedAlpha - } - } fileprivate var rootView : UIView! @IBOutlet fileprivate weak var titleLbl: UILabel! @@ -611,50 +599,56 @@ public class LGButton: UIControl { // MARK: - Touches // MARK: - override public func touchesBegan(_ touches: Set, with event: UIEvent?) - { + var touchAlpha : TouchAlphaValues = .untouched { + didSet { + updateTouchAlpha() + } + } + + var pressed : Bool = false { + didSet { + if !showTouchFeedback { + return + } + + touchAlpha = (pressed) ? .touched : .untouched + } + } + + override public func touchesBegan(_ touches: Set, with event: UIEvent?){ pressed = true } - override public func touchesEnded(_ touches: Set, with event: UIEvent?) - { + override public func touchesEnded(_ touches: Set, with event: UIEvent?){ let shouldSendActions = pressed pressed = false - if shouldSendActions - { + if shouldSendActions{ sendActions(for: .touchUpInside) } } - override public func touchesMoved(_ touches: Set, with event: UIEvent?) - { - if let touchLoc = touches.first?.location(in: self) - { + override public func touchesMoved(_ touches: Set, with event: UIEvent?){ + if let touchLoc = touches.first?.location(in: self){ if (touchLoc.x < -touchDisableRadius || touchLoc.y < -touchDisableRadius || touchLoc.x > self.bounds.size.width + touchDisableRadius || - touchLoc.y > self.bounds.size.height + touchDisableRadius) - { + touchLoc.y > self.bounds.size.height + touchDisableRadius){ pressed = false } - else if self.touchAlpha == 1.0 - { + else if self.touchAlpha == .untouched { pressed = true } } } - override public func touchesCancelled(_ touches: Set, with event: UIEvent?) - { + override public func touchesCancelled(_ touches: Set, with event: UIEvent?) { pressed = false } - func updateTouchAlpha() - { - if self.alpha != self.touchAlpha - { + func updateTouchAlpha() { + if self.alpha != self.touchAlpha.rawValue { UIView.animate(withDuration: 0.3) { - self.alpha = self.touchAlpha + self.alpha = self.touchAlpha.rawValue } } } From 5449c366a73048921de039f72849bb12fe92d1cc Mon Sep 17 00:00:00 2001 From: Guy Umbright Date: Sun, 17 Sep 2017 18:28:17 -0500 Subject: [PATCH 4/5] formatting --- LGButton/Classes/LGButton.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index e7d77b3..707c449 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -12,8 +12,7 @@ import QuartzCore @IBDesignable public class LGButton: UIControl { - enum TouchAlphaValues : CGFloat - { + enum TouchAlphaValues : CGFloat { case touched = 0.7 case untouched = 1.0 } From 1150f9d1db113f6adf6204862f328ea4a87e3c72 Mon Sep 17 00:00:00 2001 From: Lorenzo Greco Date: Sat, 23 Sep 2017 10:59:50 -0400 Subject: [PATCH 5/5] Prepare for release 1.0.3 --- LGButton.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LGButton.podspec b/LGButton.podspec index 980dabd..13db1f5 100644 --- a/LGButton.podspec +++ b/LGButton.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LGButton' - s.version = '1.0.2' + s.version = '1.0.3' s.summary = 'A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.' s.homepage = 'https://cocoapods.org/pods/LGButton' s.license = { :type => 'MIT', :file => 'LICENSE.md' }