Skip to content

Commit 1a2e19e

Browse files
committed
Merge branch 'release/1.0.3'
2 parents ab9e2cb + 1150f9d commit 1a2e19e

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

LGButton.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LGButton'
3-
s.version = '1.0.2'
3+
s.version = '1.0.3'
44
s.summary = 'A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.'
55
s.homepage = 'https://cocoapods.org/pods/LGButton'
66
s.license = { :type => 'MIT', :file => 'LICENSE.md' }

LGButton/Classes/LGButton.swift

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@
88
import UIKit
99
import QuartzCore
1010

11+
1112
@IBDesignable
1213
public class LGButton: UIControl {
1314

15+
enum TouchAlphaValues : CGFloat {
16+
case touched = 0.7
17+
case untouched = 1.0
18+
}
19+
20+
let touchDisableRadius : CGFloat = 100.0
21+
1422
let availableFontIcons = ["fa", "io", "oc", "ic", "ma", "ti", "mi"]
1523

1624
var gradient : CAGradientLayer?
17-
25+
26+
1827
fileprivate var rootView : UIView!
1928
@IBOutlet fileprivate weak var titleLbl: UILabel!
2029
@IBOutlet fileprivate weak var mainStackView: UIStackView!
@@ -589,16 +598,57 @@ public class LGButton: UIControl {
589598

590599
// MARK: - Touches
591600
// MARK:
592-
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
593-
if showTouchFeedback {
594-
alpha = 0.7
595-
UIView.animate(withDuration: 0.3) {
596-
self.alpha = 1
601+
var touchAlpha : TouchAlphaValues = .untouched {
602+
didSet {
603+
updateTouchAlpha()
604+
}
605+
}
606+
607+
var pressed : Bool = false {
608+
didSet {
609+
if !showTouchFeedback {
610+
return
597611
}
612+
613+
touchAlpha = (pressed) ? .touched : .untouched
598614
}
599615
}
616+
617+
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
618+
pressed = true
619+
}
620+
621+
override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?){
622+
let shouldSendActions = pressed
623+
pressed = false
624+
if shouldSendActions{
625+
sendActions(for: .touchUpInside)
626+
}
627+
}
628+
629+
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
630+
if let touchLoc = touches.first?.location(in: self){
631+
if (touchLoc.x < -touchDisableRadius ||
632+
touchLoc.y < -touchDisableRadius ||
633+
touchLoc.x > self.bounds.size.width + touchDisableRadius ||
634+
touchLoc.y > self.bounds.size.height + touchDisableRadius){
635+
pressed = false
636+
}
637+
else if self.touchAlpha == .untouched {
638+
pressed = true
639+
}
640+
}
641+
}
642+
643+
override public func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
644+
pressed = false
645+
}
600646

601-
override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
602-
sendActions(for: .touchUpInside)
647+
func updateTouchAlpha() {
648+
if self.alpha != self.touchAlpha.rawValue {
649+
UIView.animate(withDuration: 0.3) {
650+
self.alpha = self.touchAlpha.rawValue
651+
}
652+
}
603653
}
604654
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
![logo](media/header_btn.png)
33

4-
[![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)
4+
[![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)
55

66

77
A fully customisable subclass of the native `UIControl` which allows you to create beautiful buttons without writing any line of code.

0 commit comments

Comments
 (0)