Commit 605728de by Daniel Dahan

progressive cleanup

parent e0f8187c
...@@ -35,7 +35,7 @@ public class AddFabButton : FabButton { ...@@ -35,7 +35,7 @@ public class AddFabButton : FabButton {
// :name: prepareVerticalLine // :name: prepareVerticalLine
// //
private func prepareVerticalLine() { private func prepareVerticalLine() {
verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView.frame) / 3.0)) verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView.frame) / 3))
verticalLine.backgroundColor = .whiteColor() verticalLine.backgroundColor = .whiteColor()
verticalLine.center = backgroundColorView.center verticalLine.center = backgroundColorView.center
backgroundColorView.addSubview(verticalLine) backgroundColorView.addSubview(verticalLine)
...@@ -45,7 +45,7 @@ public class AddFabButton : FabButton { ...@@ -45,7 +45,7 @@ public class AddFabButton : FabButton {
// :name: prepareHorizontalLine // :name: prepareHorizontalLine
// //
private func prepareHorizontalLine() { private func prepareHorizontalLine() {
horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView.frame) / 3.0, lineWidth)) horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView.frame) / 3, lineWidth))
horizontalLine.backgroundColor = .whiteColor() horizontalLine.backgroundColor = .whiteColor()
horizontalLine.center = backgroundColorView.center horizontalLine.center = backgroundColorView.center
backgroundColorView.addSubview(horizontalLine) backgroundColorView.addSubview(horizontalLine)
......
...@@ -22,7 +22,7 @@ public class FabButton : MaterialButton { ...@@ -22,7 +22,7 @@ public class FabButton : MaterialButton {
/** /**
:name: lineWidth :name: lineWidth
*/ */
public var lineWidth: CGFloat = 2.0 public var lineWidth: CGFloat = 2
// //
// :name: prepareButton // :name: prepareButton
...@@ -34,6 +34,14 @@ public class FabButton : MaterialButton { ...@@ -34,6 +34,14 @@ public class FabButton : MaterialButton {
} }
// //
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = bounds.width / 2
}
//
// :name: pulseTouches // :name: pulseTouches
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
...@@ -42,7 +50,7 @@ public class FabButton : MaterialButton { ...@@ -42,7 +50,7 @@ public class FabButton : MaterialButton {
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.width, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2.0 pulseView!.layer.cornerRadius = bounds.width / 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!)
......
...@@ -33,6 +33,14 @@ public class FlatButton : MaterialButton { ...@@ -33,6 +33,14 @@ public class FlatButton : MaterialButton {
} }
// //
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches // :name: pulseTouches
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
...@@ -41,13 +49,13 @@ public class FlatButton : MaterialButton { ...@@ -41,13 +49,13 @@ public class FlatButton : MaterialButton {
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height) pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0 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!)
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(15, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal) self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
}) })
} }
......
...@@ -19,10 +19,24 @@ ...@@ -19,10 +19,24 @@
import UIKit import UIKit
public class MaterialButton : UIButton { public class MaterialButton : UIButton {
//
// :name: backgroundColorView
//
internal lazy var backgroundColorView: UIView = UIView() internal lazy var backgroundColorView: UIView = UIView()
//
// :name: pulseView
//
internal var pulseView: UIView? internal var pulseView: UIView?
/**
:name: color
*/
public var color: UIColor? public var color: UIColor?
/**
:name: pulseColor
*/
public var pulseColor: UIColor? public var pulseColor: UIColor?
/** /**
...@@ -95,16 +109,29 @@ public class MaterialButton : UIButton { ...@@ -95,16 +109,29 @@ public class MaterialButton : UIButton {
internal func pulseTouches(touches: Set<NSObject>) {} internal func pulseTouches(touches: Set<NSObject>) {}
// //
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
internal func prepareBackgroundColorView() {
backgroundColorView.frame = bounds
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
}
//
// :name: prepareView // :name: prepareView
// //
internal func prepareView() { private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false) setTranslatesAutoresizingMaskIntoConstraints(false)
} }
// //
// :name: prepareShadow // :name: prepareShadow
// //
internal func prepareShadow() { private func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1) layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5 layer.shadowOpacity = 0.5
...@@ -114,7 +141,7 @@ public class MaterialButton : UIButton { ...@@ -114,7 +141,7 @@ public class MaterialButton : UIButton {
// //
// :name: prepareContext // :name: prepareContext
// //
internal func prepareContext(rect: CGRect) { private func prepareContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext() let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context); CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect) CGContextAddEllipseInRect(context, rect)
...@@ -124,25 +151,11 @@ public class MaterialButton : UIButton { ...@@ -124,25 +151,11 @@ public class MaterialButton : UIButton {
} }
// //
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
internal func prepareBackgroundColorView() {
backgroundColorView.frame = bounds
backgroundColorView.layer.cornerRadius = bounds.width / 2.0
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0)
}
//
// :name: shrink // :name: shrink
// //
internal func shrink() { private func shrink() {
UIView.animateWithDuration(0.3, UIView.animateWithDuration(0.3,
delay: 0.0, delay: 0,
usingSpringWithDamping: 0.2, usingSpringWithDamping: 0.2,
initialSpringVelocity: 10, initialSpringVelocity: 10,
options: nil, options: nil,
...@@ -156,10 +169,10 @@ public class MaterialButton : UIButton { ...@@ -156,10 +169,10 @@ public class MaterialButton : UIButton {
// //
// :name: removePulse // :name: removePulse
// //
internal func removePulse() { private func removePulse() {
UIView.animateWithDuration(0.3, UIView.animateWithDuration(0.3,
animations: { _ in animations: { _ in
self.pulseView?.alpha = 0.0 self.pulseView?.alpha = 0
} }
) { _ in ) { _ in
self.pulseView?.removeFromSuperview() self.pulseView?.removeFromSuperview()
......
...@@ -29,6 +29,14 @@ public class RaisedButton : MaterialButton { ...@@ -29,6 +29,14 @@ public class RaisedButton : MaterialButton {
} }
// //
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches // :name: pulseTouches
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
...@@ -37,14 +45,14 @@ public class RaisedButton : MaterialButton { ...@@ -37,14 +45,14 @@ public class RaisedButton : MaterialButton {
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height) pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0 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!)
UIView.animateWithDuration(0.3, UIView.animateWithDuration(0.3,
animations: { animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(15, 1.1)
}, },
completion: nil completion: nil
) )
......
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