Commit 994edd5b by Daniel Dahan

master: merged development

parents a199e889 459aef04
Pod::Spec.new do |s|
s.name = 'MK'
s.version = '1.2.0'
s.version = '1.3.0'
s.license = { :type => "AGPLv3+", :file => "LICENSE" }
s.summary = 'A Material Design Framework In Swift'
s.homepage = 'http://materialkit.io'
......
......@@ -19,7 +19,19 @@
import UIKit
public class AddFabButton : FabButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2
//
// :name: verticalLine
//
private var verticalLine: UIView!
//
// :name: horizontalLine
//
private var horizontalLine: UIView!
//
......
......@@ -19,26 +19,22 @@
import UIKit
public class FabButton : MaterialButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
color = .redColor()
prepareShadow()
backgroundColor = .redColor()
pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = bounds.width / 2
}
//
// :name: pulseTouches
// :name: pulseBegan
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1)
......
......@@ -19,30 +19,25 @@
import UIKit
public class FlatButton : MaterialButton {
/**
:name: textColor
*/
public var textColor: UIColor?
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
pulseColor = .whiteColor()
setTitleColor(UIColor.purpleColor(), forState: .Normal)
pulseColor = .purpleColor()
backgroundColor = .clearColor()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches
// :name: pulseBegan
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
textColor = titleLabel?.textColor
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
})
}
}
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>1.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -30,9 +30,13 @@ public class MaterialButton : UIButton {
internal var pulseView: UIView?
/**
:name: color
:name: backgroundColor
*/
public var color: UIColor?
public override var backgroundColor: UIColor? {
didSet {
backgroundColorView.backgroundColor = backgroundColor
}
}
/**
:name: pulseColor
......@@ -67,7 +71,7 @@ public class MaterialButton : UIButton {
*/
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
pulseBegan(touches, withEvent: event)
}
/**
......@@ -76,16 +80,16 @@ public class MaterialButton : UIButton {
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
pulseEnded(touches, withEvent: event)
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<NSObject>, withEvent event: UIEvent!) {
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
pulseEnded(touches, withEvent: event)
}
/**
......@@ -93,7 +97,6 @@ public class MaterialButton : UIButton {
*/
final public override func drawRect(rect: CGRect) {
prepareContext(rect)
prepareShadow()
prepareButton()
prepareBackgroundColorView()
}
......@@ -106,27 +109,51 @@ public class MaterialButton : UIButton {
}
//
// :name: pulseTouches
// :name: pulseBegan
//
internal func pulseTouches(touches: Set<NSObject>) {
internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2
pulseView!.frame = CGRectMake(0, 0, bounds.height, bounds.height)
pulseView!.layer.cornerRadius = bounds.height / 2
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
}
//
// :name: pulseEnded
//
internal func pulseEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
//
// :name: prepareShadow
//
internal func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func prepareBackgroundColorView() {
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true
backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
}
......@@ -139,16 +166,6 @@ public class MaterialButton : UIButton {
}
//
// :name: prepareShadow
//
private func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
//
// :name: prepareContext
//
private func prepareContext(rect: CGRect) {
......@@ -175,18 +192,4 @@ public class MaterialButton : UIButton {
completion: nil
)
}
//
// :name: removePulse
//
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
}
......@@ -19,31 +19,26 @@
import UIKit
public class RaisedButton : MaterialButton {
/**
:name: textColor
*/
public var textColor: UIColor?
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
color = .redColor()
prepareShadow()
setTitleColor(UIColor.whiteColor(), forState: .Normal)
pulseColor = .whiteColor()
backgroundColor = .purpleColor()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches
// :name: pulseBegan
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
textColor = titleLabel?.textColor
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment