Commit fccc18e0 by Daniel Dahan

updates to button

parent 56d27cc9
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965711B8A578D0055B139 /* MaterialViewController.swift */; }; 65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965711B8A578D0055B139 /* MaterialViewController.swift */; };
65B965751B8A60A00055B139 /* MaterialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965741B8A60A00055B139 /* MaterialView.swift */; }; 65B965751B8A60A00055B139 /* MaterialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965741B8A60A00055B139 /* MaterialView.swift */; };
65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B9657D1B8A7C330055B139 /* MaterialButton.swift */; };
963832421B88DFD80015F710 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* MaterialKit.framework */; }; 963832421B88DFD80015F710 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* MaterialKit.framework */; };
9638325A1B88E31A0015F710 /* MaterialKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832581B88E31A0015F710 /* MaterialKitTests.swift */; }; 9638325A1B88E31A0015F710 /* MaterialKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832581B88E31A0015F710 /* MaterialKitTests.swift */; };
963832691B88E5BF0015F710 /* Capture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638325E1B88E5BF0015F710 /* Capture.swift */; }; 963832691B88E5BF0015F710 /* Capture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638325E1B88E5BF0015F710 /* Capture.swift */; };
...@@ -54,6 +55,7 @@ ...@@ -54,6 +55,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
65B965711B8A578D0055B139 /* MaterialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewController.swift; sourceTree = "<group>"; }; 65B965711B8A578D0055B139 /* MaterialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewController.swift; sourceTree = "<group>"; };
65B965741B8A60A00055B139 /* MaterialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialView.swift; sourceTree = "<group>"; }; 65B965741B8A60A00055B139 /* MaterialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialView.swift; sourceTree = "<group>"; };
65B9657D1B8A7C330055B139 /* MaterialButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialButton.swift; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MaterialKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 963832361B88DFD80015F710 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MaterialKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* MaterialKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MaterialKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 963832411B88DFD80015F710 /* MaterialKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MaterialKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
963832541B88E30F0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 963832541B88E30F0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
...@@ -178,6 +180,7 @@ ...@@ -178,6 +180,7 @@
963832751B88E87B0015F710 /* Button */ = { 963832751B88E87B0015F710 /* Button */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
65B9657D1B8A7C330055B139 /* MaterialButton.swift */,
963832601B88E5BF0015F710 /* FabButton.swift */, 963832601B88E5BF0015F710 /* FabButton.swift */,
963832611B88E5BF0015F710 /* FlatButton.swift */, 963832611B88E5BF0015F710 /* FlatButton.swift */,
963832651B88E5BF0015F710 /* RaisedButton.swift */, 963832651B88E5BF0015F710 /* RaisedButton.swift */,
...@@ -354,6 +357,7 @@ ...@@ -354,6 +357,7 @@
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */, 9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */, 65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */,
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */, 9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */,
65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */,
963832881B8908180015F710 /* Layout.swift in Sources */, 963832881B8908180015F710 /* Layout.swift in Sources */,
9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */, 9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */,
963832731B88E5BF0015F710 /* TextView.swift in Sources */, 963832731B88E5BF0015F710 /* TextView.swift in Sources */,
......
...@@ -20,14 +20,12 @@ import UIKit ...@@ -20,14 +20,12 @@ import UIKit
import QuartzCore import QuartzCore
public class BasicCard : MaterialPulseView { public class BasicCard : MaterialPulseView {
public lazy var cancelButton: FlatButton = FlatButton()
public var cancelButton: FlatButton = FlatButton() public lazy var otherButton: FlatButton = FlatButton()
public var otherButton: FlatButton = FlatButton() public lazy var buttonColor: UIColor = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0)
public lazy var titleLabel: UILabel = UILabel()
public var titleLabel: UILabel = UILabel() public lazy var detailTextLabel: UILabel = UILabel()
public var detailTextLabel: UILabel = UILabel() public lazy var horizontalSeparator: UIView = UIView()
public var horizontalSeparator: UIView = UIView()
public required init(coder aDecoder: NSCoder) { public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
...@@ -45,16 +43,26 @@ public class BasicCard : MaterialPulseView { ...@@ -45,16 +43,26 @@ public class BasicCard : MaterialPulseView {
super.initialize() super.initialize()
} }
func setupTitleLabel() { internal override func constrainSubviews() {
super.constrainSubviews()
addConstraints(Layout.constraint("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[cancelButton]-(10)-|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: views))
}
private func setupTitleLabel() {
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false) titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel.font = Roboto.regularWithSize(22.0) titleLabel.font = Roboto.regularWithSize(22.0)
titleLabel.textColor = UIColor.whiteColor() titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title" titleLabel.text = "Card Title"
addSubview(titleLabel) addSubview(titleLabel)
views.setObject(titleLabel, forKey: "titleLabel") views["titleLabel"] = titleLabel
} }
func setupDetailTextLabel() { private func setupDetailTextLabel() {
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false) detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel.font = Roboto.lightWithSize(16.0) detailTextLabel.font = Roboto.lightWithSize(16.0)
detailTextLabel.textColor = UIColor.whiteColor() detailTextLabel.textColor = UIColor.whiteColor()
...@@ -62,56 +70,37 @@ public class BasicCard : MaterialPulseView { ...@@ -62,56 +70,37 @@ public class BasicCard : MaterialPulseView {
detailTextLabel.numberOfLines = 0 detailTextLabel.numberOfLines = 0
detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
addSubview(detailTextLabel) addSubview(detailTextLabel)
views.setObject(detailTextLabel, forKey: "detailTextLabel") views["detailTextLabel"] = detailTextLabel
} }
func setupHorizontalLineSeparator() { private func setupHorizontalLineSeparator() {
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false) horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
horizontalSeparator.backgroundColor = UIColor.whiteColor() horizontalSeparator.backgroundColor = UIColor.whiteColor()
horizontalSeparator.alpha = 0.2 horizontalSeparator.alpha = 0.2
addSubview(horizontalSeparator) addSubview(horizontalSeparator)
views.setObject(horizontalSeparator, forKey: "line") views["horizontalSeparator"] = horizontalSeparator
} }
func setupButtons() { private func setupButtons() {
setupCancelButton() setupCancelButton()
setupOtherButton() setupOtherButton()
} }
func setupCancelButton() { private func setupCancelButton() {
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false) cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
cancelButton.setTitle("Cancel", forState: .Normal) cancelButton.setTitle("Cancel", forState: .Normal)
var orange = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0) cancelButton.setTitleColor(buttonColor, forState: .Normal)
cancelButton.setTitleColor(orange, forState: .Normal) cancelButton.pulseColor = buttonColor
cancelButton.pulseColor = orange
addSubview(cancelButton) addSubview(cancelButton)
views.setObject(cancelButton, forKey: "cancelButton") views["cancelButton"] = cancelButton
} }
func setupOtherButton() { private func setupOtherButton() {
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false) otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
otherButton.setTitle("Confirm", forState: .Normal) otherButton.setTitle("Confirm", forState: .Normal)
var orange = UIColor(red: 255.0/255.0, green: 156.0/255.0, blue: 38.0/255.0, alpha: 1.0) otherButton.setTitleColor(buttonColor, forState: .Normal)
otherButton.setTitleColor(orange, forState: .Normal) otherButton.pulseColor = buttonColor
otherButton.pulseColor = orange
addSubview(otherButton) addSubview(otherButton)
views.setObject(otherButton, forKey: "otherButton") views["otherButton"] = otherButton
}
internal override func constrainSubviews() {
super.constrainSubviews()
// Title & Detail Text Label
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[titleLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
// Horizontal line
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[line]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
// Cancel & Other Button
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[cancelButton]-(10)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[titleLabel(22)]-(10)-[detailTextLabel]-(20)-[line(1)]-(10)-[otherButton]-(10)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
} }
} }
...@@ -18,18 +18,10 @@ ...@@ -18,18 +18,10 @@
import UIKit import UIKit
public class FabButton : UIButton { public class FabButton : MaterialButton {
var lineWidth: CGFloat = 2.0 var lineWidth: CGFloat = 2.0
var color: UIColor?
var pulseColor: UIColor?
private var vLine: UIView?
private var hLine: UIView?
private var backgroundColorView: UIView?
private var pulseView: UIView?
public convenience init() { public convenience init() {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
} }
...@@ -88,17 +80,17 @@ public class FabButton : UIButton { ...@@ -88,17 +80,17 @@ public class FabButton : UIButton {
} }
func setupVerticalLine() { func setupVerticalLine() {
vLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView!.frame) / 3.0)) verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView!.frame) / 3.0))
vLine!.backgroundColor = UIColor.whiteColor() verticalLine!.backgroundColor = UIColor.whiteColor()
vLine!.center = backgroundColorView!.center verticalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(vLine!) backgroundColorView!.addSubview(verticalLine!)
} }
func setupHorizontalLine() { func setupHorizontalLine() {
hLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView!.frame) / 3.0, lineWidth)) horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView!.frame) / 3.0, lineWidth))
hLine!.backgroundColor = UIColor.whiteColor() horizontalLine!.backgroundColor = UIColor.whiteColor()
hLine!.center = backgroundColorView!.center horizontalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(hLine!) backgroundColorView!.addSubview(horizontalLine!)
} }
func applyShadow() { func applyShadow() {
......
...@@ -18,15 +18,8 @@ ...@@ -18,15 +18,8 @@
import UIKit import UIKit
public class FlatButton : UIButton { public class FlatButton : MaterialButton {
public var textColor: UIColor? public var textColor: UIColor?
public var pulseColor: UIColor?
private lazy var vLine: UIView = UIView()
private lazy var hLine: UIView = UIView()
private lazy var backgroundColorView: UIView = UIView()
private var pulseView: UIView?
public override func drawRect(rect: CGRect) { public override func drawRect(rect: CGRect) {
setupContext(rect) setupContext(rect)
...@@ -46,6 +39,7 @@ public class FlatButton : UIButton { ...@@ -46,6 +39,7 @@ public class FlatButton : UIButton {
} }
func initialize() { func initialize() {
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor() pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false) setTranslatesAutoresizingMaskIntoConstraints(false)
} }
...@@ -61,12 +55,12 @@ public class FlatButton : UIButton { ...@@ -61,12 +55,12 @@ public class FlatButton : UIButton {
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
func setupBackgroundColorView() { func setupBackgroundColorView() {
backgroundColorView.frame = self.bounds backgroundColorView!.frame = self.bounds
backgroundColorView.layer.cornerRadius = 3.0 backgroundColorView!.layer.cornerRadius = 3.0
backgroundColorView.backgroundColor = UIColor.clearColor() backgroundColorView!.backgroundColor = UIColor.clearColor()
backgroundColorView.layer.masksToBounds = true backgroundColorView!.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false backgroundColorView!.userInteractionEnabled = false
self.insertSubview(backgroundColorView, atIndex: 0) self.insertSubview(backgroundColorView!, atIndex: 0)
} }
func applyShadow() { func applyShadow() {
...@@ -101,7 +95,7 @@ public class FlatButton : UIButton { ...@@ -101,7 +95,7 @@ public class FlatButton : UIButton {
pulseView!.layer.cornerRadius = bounds.height / 2.0 pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5) pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!) backgroundColorView!.addSubview(pulseView!)
textColor = self.titleLabel?.textColor textColor = self.titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
import UIKit import UIKit
public class ImageCard : MaterialPulseView { public class ImageCard : MaterialPulseView {
public lazy var imageView: UIImageView = UIImageView() public lazy var imageView: UIImageView = UIImageView()
public required init(coder aDecoder: NSCoder) { public required init(coder aDecoder: NSCoder) {
...@@ -35,18 +34,18 @@ public class ImageCard : MaterialPulseView { ...@@ -35,18 +34,18 @@ public class ImageCard : MaterialPulseView {
super.initialize() super.initialize()
} }
func setupImageView() { internal override func constrainSubviews() {
super.constrainSubviews()
addConstraints(Layout.constraint("H:|[imageView]|", options: nil, metrics: nil, views: views))
addConstraints(Layout.constraint("V:|[imageView]|", options: nil, metrics: nil, views: views))
}
private func setupImageView() {
imageView.setTranslatesAutoresizingMaskIntoConstraints(false) imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
imageView.contentMode = .ScaleAspectFill imageView.contentMode = .ScaleAspectFill
imageView.userInteractionEnabled = false imageView.userInteractionEnabled = false
imageView.clipsToBounds = true imageView.clipsToBounds = true
addSubview(imageView) addSubview(imageView)
views.setObject(imageView, forKey: "imageView") views["imageView"] = imageView
}
internal override func constrainSubviews() {
super.constrainSubviews()
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[imageView]|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[imageView]|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
} }
} }
...@@ -25,7 +25,7 @@ public struct Layout { ...@@ -25,7 +25,7 @@ public struct Layout {
public static func width(parent: UIView, child: UIView, width: CGFloat) { public static func width(parent: UIView, child: UIView, width: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["width" : width] let metrics: Dictionary<String, AnyObject> = ["width" : width]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "H:[child(width)]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:[child(width)]", options: nil, metrics: metrics, views: views))
} }
/** /**
...@@ -34,7 +34,7 @@ public struct Layout { ...@@ -34,7 +34,7 @@ public struct Layout {
public static func height(parent: UIView, child: UIView, height: CGFloat) { public static func height(parent: UIView, child: UIView, height: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["height" : height] let metrics: Dictionary<String, AnyObject> = ["height" : height]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "V:[child(height)]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:[child(height)]", options: nil, metrics: metrics, views: views))
} }
/** /**
...@@ -51,8 +51,8 @@ public struct Layout { ...@@ -51,8 +51,8 @@ public struct Layout {
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat, left: CGFloat) { public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat, left: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "left" : left] let metrics: Dictionary<String, AnyObject> = ["top" : top, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "H:|-(left)-[child]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:|-(left)-[child]", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint(parent, constraint: "V:|-(top)-[child]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:|-(top)-[child]", options: nil, metrics: metrics, views: views))
} }
/** /**
...@@ -61,8 +61,8 @@ public struct Layout { ...@@ -61,8 +61,8 @@ public struct Layout {
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat, right: CGFloat) { public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat, right: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "right" : right] let metrics: Dictionary<String, AnyObject> = ["top" : top, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "H:[child]-(right)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:[child]-(right)-|", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint(parent, constraint: "V:|-(top)-[child]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:|-(top)-[child]", options: nil, metrics: metrics, views: views))
} }
/** /**
...@@ -71,8 +71,8 @@ public struct Layout { ...@@ -71,8 +71,8 @@ public struct Layout {
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat, left: CGFloat) { public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat, left: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "left" : left] let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "H:|-(left)-[child]", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:|-(left)-[child]", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint(parent, constraint: "V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views))
} }
/** /**
...@@ -81,16 +81,16 @@ public struct Layout { ...@@ -81,16 +81,16 @@ public struct Layout {
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat, right: CGFloat) { public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat, right: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "right" : right] let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child] let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, constraint: "H:[child]-(right)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("H:[child]-(right)-|", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint(parent, constraint: "V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views)) parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views))
} }
/** /**
:name: constraint :name: constraint
*/ */
public static func constraint(parent: UIView, constraint: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> { public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
return NSLayoutConstraint.constraintsWithVisualFormat( return NSLayoutConstraint.constraintsWithVisualFormat(
constraint, format,
options: options, options: options,
metrics: metrics, metrics: metrics,
views: views views: views
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class MaterialButton : UIButton {
public var color: UIColor?
public var pulseColor: UIColor?
internal var pulseView: UIView?
internal var verticalLine: UIView?
internal var horizontalLine: UIView?
internal var backgroundColorView: UIView?
}
...@@ -20,7 +20,7 @@ import UIKit ...@@ -20,7 +20,7 @@ import UIKit
public class MaterialPulseView : MaterialView { public class MaterialPulseView : MaterialView {
internal lazy var views: NSMutableDictionary = NSMutableDictionary() internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
public var backgroundColorView: UIView? public var backgroundColorView: UIView?
public var pulseView: UIView? public var pulseView: UIView?
...@@ -38,6 +38,20 @@ public class MaterialPulseView : MaterialView { ...@@ -38,6 +38,20 @@ public class MaterialPulseView : MaterialView {
initialize() initialize()
} }
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
}
internal func initialize() { internal func initialize() {
setupSelf() setupSelf()
setupLayer() setupLayer()
...@@ -45,6 +59,11 @@ public class MaterialPulseView : MaterialView { ...@@ -45,6 +59,11 @@ public class MaterialPulseView : MaterialView {
constrainSubviews() constrainSubviews()
} }
internal func constrainSubviews() {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[backgroundColorView]|", options: nil, metrics: nil, views: views))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[backgroundColorView]|", options: nil, metrics: nil, views: views))
}
private func setupSelf() { private func setupSelf() {
color = UIColor.clearColor() color = UIColor.clearColor()
pulseColor = UIColor.whiteColor() pulseColor = UIColor.whiteColor()
...@@ -62,7 +81,7 @@ public class MaterialPulseView : MaterialView { ...@@ -62,7 +81,7 @@ public class MaterialPulseView : MaterialView {
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
func setupBackgroundColorView() { private func setupBackgroundColorView() {
backgroundColorView = UIView() backgroundColorView = UIView()
backgroundColorView?.userInteractionEnabled = false backgroundColorView?.userInteractionEnabled = false
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false) backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
...@@ -70,29 +89,10 @@ public class MaterialPulseView : MaterialView { ...@@ -70,29 +89,10 @@ public class MaterialPulseView : MaterialView {
backgroundColorView!.backgroundColor = color backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true backgroundColorView!.layer.masksToBounds = true
addSubview(backgroundColorView!) addSubview(backgroundColorView!)
views.setObject(backgroundColorView!, forKey: "bgView") views["backgroundColorView"] = backgroundColorView
}
internal func constrainSubviews() {
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(0)-[bgView]-(0)-|", options: nil, metrics: nil, views: views as [NSObject : AnyObject]))
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
shrink()
removePulse()
} }
func pulseTouches(touches: NSSet) { private func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
...@@ -109,13 +109,13 @@ public class MaterialPulseView : MaterialView { ...@@ -109,13 +109,13 @@ public class MaterialPulseView : MaterialView {
}, completion: nil) }, completion: nil)
} }
func shrink() { private func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: { UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity self.transform = CGAffineTransformIdentity
}, completion: nil) }, completion: nil)
} }
func removePulse() { private func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0 self.pulseView?.alpha = 0.0
}) { (finished) -> Void in }) { (finished) -> Void in
......
...@@ -18,16 +18,7 @@ ...@@ -18,16 +18,7 @@
import UIKit import UIKit
public class RaisedButton : UIButton { public class RaisedButton : MaterialButton {
public var color: UIColor?
public var pulseColor: UIColor?
private var vLine: UIView = UIView()
private var hLine: UIView = UIView()
private var backgroundColorView: UIView = UIView()
private var pulseView: UIView?
public override func drawRect(rect: CGRect) { public override func drawRect(rect: CGRect) {
setupContext(rect) setupContext(rect)
setupBackgroundColorView() setupBackgroundColorView()
...@@ -47,36 +38,11 @@ public class RaisedButton : UIButton { ...@@ -47,36 +38,11 @@ public class RaisedButton : UIButton {
func initialize() { func initialize() {
color = UIColor.redColor() color = UIColor.redColor()
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor() pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false) setTranslatesAutoresizingMaskIntoConstraints(false)
} }
func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
backgroundColorView.frame = self.bounds
backgroundColorView.layer.cornerRadius = 3.0
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false
self.insertSubview(backgroundColorView, atIndex: 0)
}
func applyShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
pulseTouches(touches) pulseTouches(touches)
...@@ -94,7 +60,33 @@ public class RaisedButton : UIButton { ...@@ -94,7 +60,33 @@ public class RaisedButton : UIButton {
removePulse() removePulse()
} }
func pulseTouches(touches: NSSet) { private func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillPath(context)
CGContextRestoreGState(context);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func setupBackgroundColorView() {
backgroundColorView!.frame = self.bounds
backgroundColorView!.layer.cornerRadius = 3.0
backgroundColorView!.backgroundColor = color!
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
self.insertSubview(backgroundColorView!, atIndex: 0)
}
private func applyShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
private func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
...@@ -102,23 +94,34 @@ public class RaisedButton : UIButton { ...@@ -102,23 +94,34 @@ public class RaisedButton : UIButton {
pulseView!.layer.cornerRadius = bounds.height / 2.0 pulseView!.layer.cornerRadius = bounds.height / 2.0
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(1.05, 1.1)
}, completion: nil) },
completion: nil
)
} }
func shrink() { private func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: { UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity self.transform = CGAffineTransformIdentity
}, completion: nil) },
completion: nil
)
} }
func removePulse() { private func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in UIView.animateWithDuration(0.3,
animations: { () -> Void in
self.pulseView!.alpha = 0.0 self.pulseView!.alpha = 0.0
}) { (finished) -> Void in }) { _ in
self.pulseView!.removeFromSuperview() self.pulseView!.removeFromSuperview()
self.pulseView = nil self.pulseView = 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