Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
loregr committed Sep 23, 2017
2 parents ab9e2cb + 1150f9d commit 1a2e19e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LGButton.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
66 changes: 58 additions & 8 deletions LGButton/Classes/LGButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
import UIKit
import QuartzCore


@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?



fileprivate var rootView : UIView!
@IBOutlet fileprivate weak var titleLbl: UILabel!
@IBOutlet fileprivate weak var mainStackView: UIStackView!
Expand Down Expand Up @@ -589,16 +598,57 @@ public class LGButton: UIControl {

// MARK: - Touches
// MARK:
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if showTouchFeedback {
alpha = 0.7
UIView.animate(withDuration: 0.3) {
self.alpha = 1
var touchAlpha : TouchAlphaValues = .untouched {
didSet {
updateTouchAlpha()
}
}

var pressed : Bool = false {
didSet {
if !showTouchFeedback {
return
}

touchAlpha = (pressed) ? .touched : .untouched
}
}

override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
pressed = true
}

override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?){
let shouldSendActions = pressed
pressed = false
if shouldSendActions{
sendActions(for: .touchUpInside)
}
}

override public func touchesMoved(_ touches: Set<UITouch>, 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 == .untouched {
pressed = true
}
}
}

override public func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
pressed = false
}

override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
sendActions(for: .touchUpInside)
func updateTouchAlpha() {
if self.alpha != self.touchAlpha.rawValue {
UIView.animate(withDuration: 0.3) {
self.alpha = self.touchAlpha.rawValue
}
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 1a2e19e

Please sign in to comment.