Commit b048661a by Daniel Dahan

completed refactor

parent 156f4984
......@@ -19,8 +19,8 @@
import UIKit
public class AddFabButton : FabButton {
private lazy var verticalLine: UIView = UIView()
private lazy var horizontalLine: UIView = UIView()
private var verticalLine: UIView!
private var horizontalLine: UIView!
//
// :name: prepareButton
......
......@@ -31,35 +31,17 @@ public class FabButton : MaterialButton {
super.prepareButton()
color = .redColor()
pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = bounds.width / 2
}
}
//
// :name: pulseTouches
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
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!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1)
},
completion: nil
)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1)
})
}
}
......@@ -30,13 +30,6 @@ public class FlatButton : MaterialButton {
internal override func prepareButton() {
super.prepareButton()
pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
......@@ -45,15 +38,7 @@ public class FlatButton : MaterialButton {
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
let touch = touches.first as! UITouch
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!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
textColor = titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
......
......@@ -93,20 +93,31 @@ public class MaterialButton : UIButton {
*/
final public override func drawRect(rect: CGRect) {
prepareContext(rect)
prepareButton()
prepareShadow()
prepareButton()
prepareBackgroundColorView()
}
//
// :name: prepareButton
//
internal func prepareButton() {}
internal func prepareButton() {
backgroundColorView.frame = bounds
}
//
// :name: pulseTouches
//
internal func pulseTouches(touches: Set<NSObject>) {}
internal func pulseTouches(touches: Set<NSObject>) {
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!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
}
//
// :name: prepareBackgroundColorView
......@@ -114,7 +125,6 @@ public class MaterialButton : UIButton {
// 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
......
......@@ -31,13 +31,6 @@ public class RaisedButton : MaterialButton {
super.prepareButton()
color = .redColor()
pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3
}
......@@ -46,15 +39,7 @@ public class RaisedButton : MaterialButton {
//
internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches)
let touch = touches.first as! UITouch
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!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
textColor = titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
......
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