Commit 5bf12299 by Daniel Dahan

progressive cleanup

parent b1aeb2d5
......@@ -22,21 +22,11 @@ public class AddFabButton : FabButton {
private lazy var verticalLine: 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
// The label is not actually vertically and horizontally aligned
// Quick hack instead of subclassing UILabel and override drawTextInRect
private func preparePlus() {
public override func prepareButton() {
super.prepareButton()
prepareVerticalLine()
prepareHorizontalLine()
}
......
......@@ -29,7 +29,6 @@ public class FabButton : MaterialButton {
*/
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
/**
......@@ -37,14 +36,43 @@ public class FabButton : MaterialButton {
*/
public required init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectZero)
}
//
// :name: initialize
// :name: prepareButton
//
internal func initialize() {
color = .redColor()
internal override func prepareButton() {
super.prepareButton()
color = .redColor()
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 @@
import UIKit
public class FlatButton : MaterialButton {
public var textColor: UIColor?
public var textColor: UIColor?
/**
:name: prepareButton
*/
public override func prepareButton() {
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
pulseColor = .whiteColor()
}
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
func initialize() {
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!)
// 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 @@
import UIKit
public class MaterialButton : UIButton {
private lazy var pulseView: UIView = UIView()
internal lazy var backgroundColorView: UIView = UIView()
internal var pulseView: UIView?
public var color: UIColor?
public var pulseColor: UIColor?
......@@ -31,7 +31,6 @@ public class MaterialButton : UIButton {
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
prepareShadow()
}
/**
......@@ -40,7 +39,6 @@ public class MaterialButton : UIButton {
public required override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
prepareShadow()
}
/**
......@@ -82,16 +80,21 @@ public class MaterialButton : UIButton {
final public override func drawRect(rect: CGRect) {
prepareContext(rect)
prepareButton()
}
/**
:name: prepareButton
*/
public func prepareButton() {
prepareShadow()
prepareBackgroundColorView()
}
//
// :name: prepareButton
//
internal func prepareButton() {}
//
// :name: pulseTouches
//
internal func pulseTouches(touches: Set<NSObject>) {}
//
// :name: prepareView
//
internal func prepareView() {
......@@ -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
//
internal func shrink() {
......@@ -176,10 +159,11 @@ public class MaterialButton : UIButton {
internal func removePulse() {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView.alpha = 0.0
self.pulseView?.alpha = 0.0
}
) { _ in
self.pulseView.removeFromSuperview()
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
}
......@@ -19,19 +19,35 @@
import UIKit
public class RaisedButton : MaterialButton {
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
func initialize() {
//
// :name: prepareButton
//
internal override func prepareButton() {
super.prepareButton()
color = .redColor()
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