Commit 5bf12299 by Daniel Dahan

progressive cleanup

parent b1aeb2d5
...@@ -22,21 +22,11 @@ public class AddFabButton : FabButton { ...@@ -22,21 +22,11 @@ public class AddFabButton : FabButton {
private lazy var verticalLine: UIView = UIView() private lazy var verticalLine: UIView = UIView()
private lazy var horizontalLine: UIView = UIView() private lazy var horizontalLine: UIView = UIView()
/**
:name: prepareButton
*/
public override func prepareButton() {
super.prepareButton()
preparePlus()
}
// //
// :name: preparePlus // :name: prepareButton
// //
// I make the + with two views because public override func prepareButton() {
// The label is not actually vertically and horizontally aligned super.prepareButton()
// Quick hack instead of subclassing UILabel and override drawTextInRect
private func preparePlus() {
prepareVerticalLine() prepareVerticalLine()
prepareHorizontalLine() prepareHorizontalLine()
} }
......
...@@ -29,7 +29,6 @@ public class FabButton : MaterialButton { ...@@ -29,7 +29,6 @@ public class FabButton : MaterialButton {
*/ */
public required init(coder aDecoder: NSCoder) { public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
initialize()
} }
/** /**
...@@ -37,14 +36,43 @@ public class FabButton : MaterialButton { ...@@ -37,14 +36,43 @@ public class FabButton : MaterialButton {
*/ */
public required init(frame: CGRect) { public required init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
initialize() }
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectZero)
} }
// //
// :name: initialize // :name: prepareButton
// //
internal func initialize() { internal override func prepareButton() {
color = .redColor() super.prepareButton()
color = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
} }
//
// :name: pulseTouches
//
// public 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.0
// 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
// )
// }
} }
...@@ -19,27 +19,34 @@ ...@@ -19,27 +19,34 @@
import UIKit import UIKit
public class FlatButton : MaterialButton { public class FlatButton : MaterialButton {
public var textColor: UIColor? public var textColor: UIColor?
/** //
:name: prepareButton // :name: prepareButton
*/ //
public override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
pulseColor = .whiteColor()
} }
public required init(coder aDecoder: NSCoder) { //
super.init(coder: aDecoder) // :name: pulseTouches
initialize() //
// public override func pulseTouches(touches: Set<NSObject>) {
} // super.pulseTouches(touches)
// let touch = touches.first as! UITouch
public required init(frame: CGRect) { // let touchLocation = touch.locationInView(self)
super.init(frame: frame) // pulseView = UIView()
initialize() // pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
} // pulseView!.layer.cornerRadius = bounds.height / 2.0
// pulseView!.center = touchLocation
func initialize() { // pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
pulseColor = .whiteColor() // backgroundColorView.addSubview(pulseView!)
} // textColor = self.titleLabel?.textColor
// UIView.animateWithDuration(0.3, animations: {
// self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
// self.transform = CGAffineTransformMakeScale(1.05, 1.1)
// self.setTitleColor(.whiteColor(), forState: .Normal)
// }, completion: nil)
// }
} }
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
import UIKit import UIKit
public class MaterialButton : UIButton { public class MaterialButton : UIButton {
private lazy var pulseView: UIView = UIView()
internal lazy var backgroundColorView: UIView = UIView() internal lazy var backgroundColorView: UIView = UIView()
internal var pulseView: UIView?
public var color: UIColor? public var color: UIColor?
public var pulseColor: UIColor? public var pulseColor: UIColor?
...@@ -31,7 +31,6 @@ public class MaterialButton : UIButton { ...@@ -31,7 +31,6 @@ public class MaterialButton : UIButton {
public required init(coder aDecoder: NSCoder) { public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
prepareShadow()
} }
/** /**
...@@ -40,7 +39,6 @@ public class MaterialButton : UIButton { ...@@ -40,7 +39,6 @@ public class MaterialButton : UIButton {
public required override init(frame: CGRect) { public required override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
prepareShadow()
} }
/** /**
...@@ -82,16 +80,21 @@ public class MaterialButton : UIButton { ...@@ -82,16 +80,21 @@ public class MaterialButton : UIButton {
final public override func drawRect(rect: CGRect) { final public override func drawRect(rect: CGRect) {
prepareContext(rect) prepareContext(rect)
prepareButton() prepareButton()
} prepareShadow()
/**
:name: prepareButton
*/
public func prepareButton() {
prepareBackgroundColorView() prepareBackgroundColorView()
} }
// //
// :name: prepareButton
//
internal func prepareButton() {}
//
// :name: pulseTouches
//
internal func pulseTouches(touches: Set<NSObject>) {}
//
// :name: prepareView // :name: prepareView
// //
internal func prepareView() { internal func prepareView() {
...@@ -135,26 +138,6 @@ public class MaterialButton : UIButton { ...@@ -135,26 +138,6 @@ public class MaterialButton : UIButton {
} }
// //
// :name: pulseTouches
//
internal func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView.frame = CGRectMake(0, 0, bounds.width, bounds.height)
pulseView.layer.cornerRadius = bounds.width / 2.0
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
)
}
//
// :name: shrink // :name: shrink
// //
internal func shrink() { internal func shrink() {
...@@ -176,10 +159,11 @@ public class MaterialButton : UIButton { ...@@ -176,10 +159,11 @@ public class MaterialButton : UIButton {
internal func removePulse() { internal func removePulse() {
UIView.animateWithDuration(0.3, UIView.animateWithDuration(0.3,
animations: { _ in animations: { _ in
self.pulseView.alpha = 0.0 self.pulseView?.alpha = 0.0
} }
) { _ in ) { _ in
self.pulseView.removeFromSuperview() self.pulseView?.removeFromSuperview()
self.pulseView = nil
} }
} }
} }
...@@ -19,19 +19,35 @@ ...@@ -19,19 +19,35 @@
import UIKit import UIKit
public class RaisedButton : MaterialButton { public class RaisedButton : MaterialButton {
public required init(coder aDecoder: NSCoder) { //
super.init(coder: aDecoder) // :name: prepareButton
initialize() //
} internal override func prepareButton() {
super.prepareButton()
public required init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
func initialize() {
color = .redColor() color = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
} }
//
// :name: pulseTouches
//
// public 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!)
// UIView.animateWithDuration(0.3,
// animations: {
// self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
// self.transform = CGAffineTransformMakeScale(1.05, 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