Commit 459aef04 by Daniel Dahan

issue-17: updated button interface

parent ae77e281
......@@ -24,7 +24,14 @@ public class AddFabButton : FabButton {
*/
public var lineWidth: CGFloat = 2
//
// :name: verticalLine
//
private var verticalLine: UIView!
//
// :name: horizontalLine
//
private var horizontalLine: UIView!
//
......
......@@ -24,16 +24,17 @@ public class FabButton : MaterialButton {
//
internal override func prepareButton() {
super.prepareButton()
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)
......
......@@ -18,14 +18,26 @@
import UIKit
public class FlatButton : RaisedButton {
public class FlatButton : MaterialButton {
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
setTitleColor(UIColor.purpleColor(), forState: .Normal)
pulseColor = .purpleColor()
backgroundColor = .clearColor()
pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseBegan
//
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)
})
}
}
......@@ -71,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)
}
/**
......@@ -80,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)
}
/**
......@@ -97,7 +97,6 @@ public class MaterialButton : UIButton {
*/
final public override func drawRect(rect: CGRect) {
prepareContext(rect)
prepareShadow()
prepareButton()
prepareBackgroundColorView()
}
......@@ -110,20 +109,44 @@ 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
......@@ -143,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) {
......@@ -179,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,47 +19,27 @@
import UIKit
public class RaisedButton : MaterialButton {
/**
:name: pulseTitleColor
*/
public var pulseTitleColor: UIColor?
/**
:name: titleColor
*/
public var titleColor: UIColor? {
didSet {
setTitleColor(titleColor, forState: .Normal)
}
}
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
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)
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)
if let c = self.pulseTitleColor {
self.setTitleColor(c, forState: .Normal)
}
}) { _ in
if let c = self.titleColor {
UIView.animateWithDuration(0.3, animations: {
self.setTitleColor(c, 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