Commit 459aef04 by Daniel Dahan

issue-17: updated button interface

parent ae77e281
...@@ -24,7 +24,14 @@ public class AddFabButton : FabButton { ...@@ -24,7 +24,14 @@ public class AddFabButton : FabButton {
*/ */
public var lineWidth: CGFloat = 2 public var lineWidth: CGFloat = 2
//
// :name: verticalLine
//
private var verticalLine: UIView! private var verticalLine: UIView!
//
// :name: horizontalLine
//
private var horizontalLine: UIView! private var horizontalLine: UIView!
// //
......
...@@ -24,16 +24,17 @@ public class FabButton : MaterialButton { ...@@ -24,16 +24,17 @@ public class FabButton : MaterialButton {
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
prepareShadow()
backgroundColor = .redColor() backgroundColor = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = bounds.width / 2 backgroundColorView.layer.cornerRadius = bounds.width / 2
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseTouches(touches) super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3) self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1) self.transform = CGAffineTransformMakeScale(1.1, 1.1)
......
...@@ -18,14 +18,26 @@ ...@@ -18,14 +18,26 @@
import UIKit import UIKit
public class FlatButton : RaisedButton { public class FlatButton : MaterialButton {
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
setTitleColor(UIColor.purpleColor(), forState: .Normal)
pulseColor = .purpleColor()
backgroundColor = .clearColor() backgroundColor = .clearColor()
pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = 3 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 { ...@@ -71,7 +71,7 @@ public class MaterialButton : UIButton {
*/ */
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
pulseTouches(touches) pulseBegan(touches, withEvent: event)
} }
/** /**
...@@ -80,16 +80,16 @@ public class MaterialButton : UIButton { ...@@ -80,16 +80,16 @@ public class MaterialButton : UIButton {
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event) super.touchesEnded(touches, withEvent: event)
shrink() shrink()
removePulse() pulseEnded(touches, withEvent: event)
} }
/** /**
:name: touchesCancelled :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) super.touchesCancelled(touches, withEvent: event)
shrink() shrink()
removePulse() pulseEnded(touches, withEvent: event)
} }
/** /**
...@@ -97,7 +97,6 @@ public class MaterialButton : UIButton { ...@@ -97,7 +97,6 @@ public class MaterialButton : UIButton {
*/ */
final public override func drawRect(rect: CGRect) { final public override func drawRect(rect: CGRect) {
prepareContext(rect) prepareContext(rect)
prepareShadow()
prepareButton() prepareButton()
prepareBackgroundColorView() prepareBackgroundColorView()
} }
...@@ -110,20 +109,44 @@ public class MaterialButton : UIButton { ...@@ -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 touch = touches.first as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height) pulseView!.frame = CGRectMake(0, 0, bounds.height, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2 pulseView!.layer.cornerRadius = bounds.height / 2
pulseView!.center = touchLocation pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5) pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!) 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 // :name: prepareBackgroundColorView
// //
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
...@@ -143,16 +166,6 @@ public class MaterialButton : UIButton { ...@@ -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 // :name: prepareContext
// //
private func prepareContext(rect: CGRect) { private func prepareContext(rect: CGRect) {
...@@ -179,18 +192,4 @@ public class MaterialButton : UIButton { ...@@ -179,18 +192,4 @@ public class MaterialButton : UIButton {
completion: nil 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 @@ ...@@ -19,47 +19,27 @@
import UIKit import UIKit
public class RaisedButton : MaterialButton { public class RaisedButton : MaterialButton {
/**
:name: pulseTitleColor
*/
public var pulseTitleColor: UIColor?
/**
:name: titleColor
*/
public var titleColor: UIColor? {
didSet {
setTitleColor(titleColor, forState: .Normal)
}
}
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
prepareShadow()
setTitleColor(UIColor.whiteColor(), forState: .Normal)
pulseColor = .whiteColor() pulseColor = .whiteColor()
backgroundColor = .purpleColor()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseTouches(touches) super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) 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