Commit fccc18e0 by Daniel Dahan

updates to button

parent 56d27cc9
......@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965711B8A578D0055B139 /* MaterialViewController.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 */; };
9638325A1B88E31A0015F710 /* MaterialKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832581B88E31A0015F710 /* MaterialKitTests.swift */; };
963832691B88E5BF0015F710 /* Capture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638325E1B88E5BF0015F710 /* Capture.swift */; };
......@@ -54,6 +55,7 @@
/* Begin PBXFileReference section */
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>"; };
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; };
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>"; };
......@@ -178,6 +180,7 @@
963832751B88E87B0015F710 /* Button */ = {
isa = PBXGroup;
children = (
65B9657D1B8A7C330055B139 /* MaterialButton.swift */,
963832601B88E5BF0015F710 /* FabButton.swift */,
963832611B88E5BF0015F710 /* FlatButton.swift */,
963832651B88E5BF0015F710 /* RaisedButton.swift */,
......@@ -354,6 +357,7 @@
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
65B965721B8A578D0055B139 /* MaterialViewController.swift in Sources */,
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */,
65B9657E1B8A7C330055B139 /* MaterialButton.swift in Sources */,
963832881B8908180015F710 /* Layout.swift in Sources */,
9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */,
963832731B88E5BF0015F710 /* TextView.swift in Sources */,
......
......@@ -20,14 +20,12 @@ import UIKit
import QuartzCore
public class BasicCard : MaterialPulseView {
public var cancelButton: FlatButton = FlatButton()
public var otherButton: FlatButton = FlatButton()
public var titleLabel: UILabel = UILabel()
public var detailTextLabel: UILabel = UILabel()
public var horizontalSeparator: UIView = UIView()
public lazy var cancelButton: FlatButton = FlatButton()
public lazy 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 lazy var detailTextLabel: UILabel = UILabel()
public lazy var horizontalSeparator: UIView = UIView()
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
......@@ -44,17 +42,27 @@ public class BasicCard : MaterialPulseView {
setupButtons()
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.font = Roboto.regularWithSize(22.0)
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title"
addSubview(titleLabel)
views.setObject(titleLabel, forKey: "titleLabel")
views["titleLabel"] = titleLabel
}
func setupDetailTextLabel() {
private func setupDetailTextLabel() {
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel.font = Roboto.lightWithSize(16.0)
detailTextLabel.textColor = UIColor.whiteColor()
......@@ -62,56 +70,37 @@ public class BasicCard : MaterialPulseView {
detailTextLabel.numberOfLines = 0
detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
addSubview(detailTextLabel)
views.setObject(detailTextLabel, forKey: "detailTextLabel")
views["detailTextLabel"] = detailTextLabel
}
func setupHorizontalLineSeparator() {
private func setupHorizontalLineSeparator() {
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
horizontalSeparator.backgroundColor = UIColor.whiteColor()
horizontalSeparator.alpha = 0.2
addSubview(horizontalSeparator)
views.setObject(horizontalSeparator, forKey: "line")
views["horizontalSeparator"] = horizontalSeparator
}
func setupButtons() {
private func setupButtons() {
setupCancelButton()
setupOtherButton()
}
func setupCancelButton() {
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
private func setupCancelButton() {
cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
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(orange, forState: .Normal)
cancelButton.pulseColor = orange
cancelButton.setTitleColor(buttonColor, forState: .Normal)
cancelButton.pulseColor = buttonColor
addSubview(cancelButton)
views.setObject(cancelButton, forKey: "cancelButton")
views["cancelButton"] = cancelButton
}
func setupOtherButton() {
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
private func setupOtherButton() {
otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
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(orange, forState: .Normal)
otherButton.pulseColor = orange
otherButton.setTitleColor(buttonColor, forState: .Normal)
otherButton.pulseColor = buttonColor
addSubview(otherButton)
views.setObject(otherButton, forKey: "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]))
views["otherButton"] = otherButton
}
}
......@@ -18,19 +18,11 @@
import UIKit
public class FabButton : UIButton {
public class FabButton : MaterialButton {
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)
}
......@@ -88,17 +80,17 @@ public class FabButton : UIButton {
}
func setupVerticalLine() {
vLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView!.frame) / 3.0))
vLine!.backgroundColor = UIColor.whiteColor()
vLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(vLine!)
verticalLine = UIView(frame: CGRectMake(0, 0, lineWidth, CGRectGetHeight(backgroundColorView!.frame) / 3.0))
verticalLine!.backgroundColor = UIColor.whiteColor()
verticalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(verticalLine!)
}
func setupHorizontalLine() {
hLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView!.frame) / 3.0, lineWidth))
hLine!.backgroundColor = UIColor.whiteColor()
hLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(hLine!)
horizontalLine = UIView(frame: CGRectMake(0, 0, CGRectGetWidth(backgroundColorView!.frame) / 3.0, lineWidth))
horizontalLine!.backgroundColor = UIColor.whiteColor()
horizontalLine!.center = backgroundColorView!.center
backgroundColorView!.addSubview(horizontalLine!)
}
func applyShadow() {
......
......@@ -18,16 +18,9 @@
import UIKit
public class FlatButton : UIButton {
public class FlatButton : MaterialButton {
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) {
setupContext(rect)
setupBackgroundColorView()
......@@ -46,6 +39,7 @@ public class FlatButton : UIButton {
}
func initialize() {
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
}
......@@ -61,12 +55,12 @@ public class FlatButton : UIButton {
// 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 = UIColor.clearColor()
backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false
self.insertSubview(backgroundColorView, atIndex: 0)
backgroundColorView!.frame = self.bounds
backgroundColorView!.layer.cornerRadius = 3.0
backgroundColorView!.backgroundColor = UIColor.clearColor()
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
self.insertSubview(backgroundColorView!, atIndex: 0)
}
func applyShadow() {
......@@ -101,7 +95,7 @@ public class FlatButton : UIButton {
pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
backgroundColorView!.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
......
......@@ -19,7 +19,6 @@
import UIKit
public class ImageCard : MaterialPulseView {
public lazy var imageView: UIImageView = UIImageView()
public required init(coder aDecoder: NSCoder) {
......@@ -34,19 +33,19 @@ public class ImageCard : MaterialPulseView {
setupImageView()
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.contentMode = .ScaleAspectFill
imageView.userInteractionEnabled = false
imageView.clipsToBounds = true
addSubview(imageView)
views.setObject(imageView, forKey: "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]))
views["imageView"] = imageView
}
}
......@@ -25,7 +25,7 @@ public struct Layout {
public static func width(parent: UIView, child: UIView, width: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["width" : width]
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 {
public static func height(parent: UIView, child: UIView, height: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["height" : height]
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 {
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat, left: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, 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("H:|-(left)-[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 {
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat, right: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, 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("H:[child]-(right)-|", 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 {
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat, left: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "left" : left]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, 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("H:|-(left)-[child]", 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 {
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat, right: CGFloat) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "right" : right]
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint(parent, 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("H:[child]-(right)-|", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views))
}
/**
: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(
constraint,
format,
options: options,
metrics: metrics,
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
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 pulseView: UIView?
......@@ -37,14 +37,33 @@ public class MaterialPulseView : MaterialView {
super.init(frame: frame)
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() {
setupSelf()
setupLayer()
setupBackgroundColorView()
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() {
color = UIColor.clearColor()
pulseColor = UIColor.whiteColor()
......@@ -62,7 +81,7 @@ public class MaterialPulseView : MaterialView {
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
private func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView?.userInteractionEnabled = false
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
......@@ -70,29 +89,10 @@ public class MaterialPulseView : MaterialView {
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
addSubview(backgroundColorView!)
views.setObject(backgroundColorView!, forKey: "bgView")
}
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)
views["backgroundColorView"] = backgroundColorView
}
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 touchLocation = touch.locationInView(self)
pulseView = UIView()
......@@ -109,13 +109,13 @@ public class MaterialPulseView : MaterialView {
}, completion: nil)
}
func shrink() {
private func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
}
func removePulse() {
private func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
......
......@@ -18,16 +18,7 @@
import UIKit
public class RaisedButton : UIButton {
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 class RaisedButton : MaterialButton {
public override func drawRect(rect: CGRect) {
setupContext(rect)
setupBackgroundColorView()
......@@ -47,36 +38,11 @@ public class RaisedButton : UIButton {
func initialize() {
color = UIColor.redColor()
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor()
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) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
......@@ -94,7 +60,33 @@ public class RaisedButton : UIButton {
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 touchLocation = touch.locationInView(self)
pulseView = UIView()
......@@ -102,25 +94,36 @@ public class RaisedButton : UIButton {
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)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1)
},
completion: nil
)
}
func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
private func shrink() {
UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity
},
completion: nil
)
}
func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView!.alpha = 0.0
}) { (finished) -> Void in
self.pulseView!.removeFromSuperview()
self.pulseView = nil
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { () -> Void in
self.pulseView!.alpha = 0.0
}) { _ in
self.pulseView!.removeFromSuperview()
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