Commit 605728de by Daniel Dahan

progressive cleanup

parent e0f8187c
......@@ -35,7 +35,7 @@ public class AddFabButton : FabButton {
// :name: 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.center = backgroundColorView.center
backgroundColorView.addSubview(verticalLine)
......@@ -45,7 +45,7 @@ public class AddFabButton : FabButton {
// :name: 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.center = backgroundColorView.center
backgroundColorView.addSubview(horizontalLine)
......
......@@ -22,7 +22,7 @@ public class FabButton : MaterialButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2.0
public var lineWidth: CGFloat = 2
//
// :name: prepareButton
......@@ -34,6 +34,14 @@ public class FabButton : MaterialButton {
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = bounds.width / 2
}
//
// :name: pulseTouches
//
internal override func pulseTouches(touches: Set<NSObject>) {
......@@ -42,7 +50,7 @@ public class FabButton : MaterialButton {
let touchLocation = touch.locationInView(self)
pulseView = UIView()
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!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
......
......@@ -33,6 +33,14 @@ public class FlatButton : MaterialButton {
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches
//
internal override func pulseTouches(touches: Set<NSObject>) {
......@@ -41,13 +49,13 @@ public class FlatButton : MaterialButton {
let touchLocation = touch.locationInView(self)
pulseView = UIView()
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!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
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)
})
}
......
......@@ -19,10 +19,24 @@
import UIKit
public class MaterialButton : UIButton {
//
// :name: backgroundColorView
//
internal lazy var backgroundColorView: UIView = UIView()
//
// :name: pulseView
//
internal var pulseView: UIView?
/**
:name: color
*/
public var color: UIColor?
/**
:name: pulseColor
*/
public var pulseColor: UIColor?
/**
......@@ -95,16 +109,29 @@ public class MaterialButton : UIButton {
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
//
internal func prepareView() {
private func prepareView() {
setTranslatesAutoresizingMaskIntoConstraints(false)
}
//
// :name: prepareShadow
//
internal func prepareShadow() {
private func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
......@@ -114,7 +141,7 @@ public class MaterialButton : UIButton {
//
// :name: prepareContext
//
internal func prepareContext(rect: CGRect) {
private func prepareContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect)
......@@ -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
//
internal func shrink() {
private func shrink() {
UIView.animateWithDuration(0.3,
delay: 0.0,
delay: 0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
......@@ -156,10 +169,10 @@ public class MaterialButton : UIButton {
//
// :name: removePulse
//
internal func removePulse() {
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0.0
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
......
......@@ -29,6 +29,14 @@ public class RaisedButton : MaterialButton {
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
//
// :name: pulseTouches
//
internal override func pulseTouches(touches: Set<NSObject>) {
......@@ -37,14 +45,14 @@ public class RaisedButton : MaterialButton {
let touchLocation = touch.locationInView(self)
pulseView = UIView()
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!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.transform = CGAffineTransformMakeScale(15, 1.1)
},
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