Commit 98c391be by Daniel Dahan

merge from development

parents a53b0a9e 8f76d609
Pod::Spec.new do |s|
s.name = 'MaterialKit'
s.name = 'MK'
s.version = '1.0.0'
s.license = { :type => "AGPLv3+", :file => "LICENSE" }
s.summary = 'A Material Design Framework In Swift'
......
......@@ -7,6 +7,9 @@
objects = {
/* 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 */; };
......@@ -32,6 +35,8 @@
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */; };
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */; };
9A94D0FD1B895EA500F586A5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */; };
9A94D1091B8A3F5100F586A5 /* MaterialPulseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A94D1081B8A3F5100F586A5 /* MaterialPulseView.swift */; };
9A94D10B1B8A485C00F586A5 /* ImageCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A94D10A1B8A485C00F586A5 /* ImageCard.swift */; };
9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; };
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; };
9AAC385F1B8957A200FE6B2D /* BasicCard.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC384C1B89528900FE6B2D /* BasicCard.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -48,6 +53,9 @@
/* End PBXContainerItemProxy section */
/* 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>"; };
......@@ -63,6 +71,8 @@
963832671B88E5BF0015F710 /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; };
963832681B88E5BF0015F710 /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
963832871B8908180015F710 /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; };
9A94D1081B8A3F5100F586A5 /* MaterialPulseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseView.swift; sourceTree = "<group>"; };
9A94D10A1B8A485C00F586A5 /* ImageCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCard.swift; sourceTree = "<group>"; };
9AAC384C1B89528900FE6B2D /* BasicCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCard.swift; sourceTree = "<group>"; };
9AAC38531B89559900FE6B2D /* Roboto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Roboto.swift; sourceTree = "<group>"; };
9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = "<group>"; };
......@@ -89,6 +99,16 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
65B965731B8A58E60055B139 /* View */ = {
isa = PBXGroup;
children = (
65B965741B8A60A00055B139 /* MaterialView.swift */,
9A94D1081B8A3F5100F586A5 /* MaterialPulseView.swift */,
65B965711B8A578D0055B139 /* MaterialViewController.swift */,
);
name = View;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
isa = PBXGroup;
children = (
......@@ -114,6 +134,7 @@
9638325C1B88E3420015F710 /* Supporting Files */,
9AAC38521B89553800FE6B2D /* Font */,
963832861B8907FE0015F710 /* Layout */,
65B965731B8A58E60055B139 /* View */,
963832761B88E8990015F710 /* Text */,
963832751B88E87B0015F710 /* Button */,
9AAC384B1B89524E00FE6B2D /* Card */,
......@@ -159,6 +180,7 @@
963832751B88E87B0015F710 /* Button */ = {
isa = PBXGroup;
children = (
65B9657D1B8A7C330055B139 /* MaterialButton.swift */,
963832601B88E5BF0015F710 /* FabButton.swift */,
963832611B88E5BF0015F710 /* FlatButton.swift */,
963832651B88E5BF0015F710 /* RaisedButton.swift */,
......@@ -188,6 +210,7 @@
isa = PBXGroup;
children = (
9AAC384C1B89528900FE6B2D /* BasicCard.swift */,
9A94D10A1B8A485C00F586A5 /* ImageCard.swift */,
);
name = Card;
sourceTree = "<group>";
......@@ -325,11 +348,16 @@
buildActionMask = 2147483647;
files = (
963832691B88E5BF0015F710 /* Capture.swift in Sources */,
9A94D10B1B8A485C00F586A5 /* ImageCard.swift in Sources */,
9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */,
9A94D1091B8A3F5100F586A5 /* MaterialPulseView.swift in Sources */,
9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */,
65B965751B8A60A00055B139 /* MaterialView.swift in Sources */,
963832711B88E5BF0015F710 /* Text.swift in Sources */,
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 */,
......
![MaterialKit](https://github.com/GraphKit/MaterialKit/blob/development/MaterialKitLogo.png)
![MaterialKit](http://materialkit.io/MaterialKitLogo.png)
......@@ -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)
}
......@@ -75,6 +67,7 @@ public class FabButton : UIButton {
backgroundColorView!.layer.cornerRadius = bounds.width / 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
backgroundColorView!.userInteractionEnabled = false
insertSubview(backgroundColorView!, atIndex: 0)
}
......@@ -87,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() {
......@@ -107,17 +100,23 @@ public class FabButton : UIButton {
layer.shadowRadius = 5
}
override public func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
override public func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
......@@ -127,16 +126,26 @@ public class FabButton : UIButton {
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)
},
completion: nil
)
}
func shrink() {
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
self.transform = CGAffineTransformIdentity
}, completion: nil)
UIView.animateWithDuration(0.3,
delay: 0.0,
usingSpringWithDamping: 0.2,
initialSpringVelocity: 10,
options: nil,
animations: {
self.transform = CGAffineTransformIdentity
},
completion: nil
)
}
func removePulse() {
......
......@@ -18,16 +18,9 @@
import UIKit
public class FlatButton : UIButton {
public class FlatButton : MaterialButton {
public var textColor: 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) {
setupContext(rect)
setupBackgroundColorView()
......@@ -46,6 +39,7 @@ public class FlatButton : UIButton {
}
func initialize() {
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
}
......@@ -61,11 +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
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() {
......@@ -76,11 +71,19 @@ public class FlatButton : UIButton {
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
pulseTouches(touches)
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
shrink()
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
......@@ -92,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)
......
//
// 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 ImageCard : MaterialPulseView {
public lazy var imageView: UIImageView = UIImageView()
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public required init(frame: CGRect) {
super.init(frame: frame)
}
internal override func initialize() {
setupImageView()
super.initialize()
}
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["imageView"] = imageView
}
}
......@@ -19,43 +19,81 @@
import UIKit
public struct Layout {
public static func topRight(parent: UIView, child: UIView, width: CGFloat, height: CGFloat, top: CGFloat, right: CGFloat) {
parent.addSubview(child)
var metrics = ["width" : width, "height" : height, "top" : top, "right" : right]
var views = ["view" : child]
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(child, forKey: "child")
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[child(width)]-(right)-|", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(top)-[child(height)]", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
/**
:name: width
*/
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("H:[child(width)]", options: nil, metrics: metrics, views: views))
}
public static func topLeft(parent: UIView, child: UIView, width: CGFloat, height: CGFloat, top: CGFloat, left: CGFloat) {
parent.addSubview(child)
var metrics = ["width" : width, "height" : height, "top" : top, "left" : left]
var views = ["view" : child]
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(child, forKey: "child")
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(left)-[child(width)]", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-(top)-[child(height)]", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
/**
:name: height
*/
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("V:[child(height)]", options: nil, metrics: metrics, views: views))
}
public static func bottomRight(parent: UIView, child: UIView, width: CGFloat, height: CGFloat, bottom: CGFloat, right: CGFloat) {
parent.addSubview(child)
var metrics = ["width" : width, "height" : height, "bottom" : bottom, "right" : right]
var views = ["view" : child]
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(child, forKey: "child")
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[child(width)]-(right)-|", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[child(height)]-(bottom)-|", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
/**
:name: size
*/
public static func size(parent: UIView, child: UIView, width: CGFloat, height: CGFloat) {
Layout.width(parent, child: child, width: width)
Layout.height(parent, child: child, height: height)
}
public static func bottomLeft(parent: UIView, child: UIView, width: CGFloat, height: CGFloat, bottom: CGFloat, left: CGFloat) {
parent.addSubview(child)
var metrics = ["width" : width, "height" : height, "bottom" : bottom, "left" : left]
var views = ["view" : child]
var viewBindingsDict: NSMutableDictionary = NSMutableDictionary()
viewBindingsDict.setValue(child, forKey: "child")
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(left)-[child(width)]", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
parent.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[child(height)]-(bottom)-|", options: nil, metrics: metrics, views: viewBindingsDict as [NSObject : AnyObject]))
/**
:name: alignFromTopLeft
*/
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("H:|-(left)-[child]", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: nil, metrics: metrics, views: views))
}
/**
:name: alignFromTopRight
*/
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("H:[child]-(right)-|", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: nil, metrics: metrics, views: views))
}
/**
:name: alignFromBottomLeft
*/
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("H:|-(left)-[child]", options: nil, metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: nil, metrics: metrics, views: views))
}
/**
:name: alignFromBottomRight
*/
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("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(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
return NSLayoutConstraint.constraintsWithVisualFormat(
format,
options: options,
metrics: metrics,
views: views
) as! Array<NSLayoutConstraint>
}
}
//
// 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?
}
//
// 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 MaterialPulseView : MaterialView {
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
public var backgroundColorView: UIView?
public var pulseView: UIView?
public var color: UIColor?
public var pulseColor: UIColor?
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
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()
setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColor = UIColor(red: 66.0/255.0, green: 91.0/255.0, blue: 103.0/255.0, alpha: 1.0)
}
private func setupLayer() {
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSizeMake(0.5, 0.5)
layer.shadowRadius = 5.0
layer.shadowOpacity = 0.4
layer.cornerRadius = 2.0
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView?.userInteractionEnabled = false
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView!.layer.cornerRadius = 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
addSubview(backgroundColorView!)
views["backgroundColorView"] = backgroundColorView
}
private func pulseTouches(touches: NSSet) {
let touch = touches.allObjects.last as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView?.setTranslatesAutoresizingMaskIntoConstraints(false)
var width = bounds.size.width / 3.0
pulseView!.frame = CGRectMake(0, 0, width, width)
pulseView!.layer.cornerRadius = width / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.1)
backgroundColorView!.addSubview(pulseView!)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, 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)
}
private func removePulse() {
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.pulseView?.alpha = 0.0
}) { (finished) -> Void in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
}
//
// 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 MaterialView : UIView {
/**
:name: topLeft
*/
public func topLeft(child: UIView, top: CGFloat, left: CGFloat) {
Layout.alignFromTopLeft(self, child: child, top: top, left: left)
}
/**
:name: topRight
*/
public func topRight(child: UIView, top: CGFloat, right: CGFloat) {
Layout.alignFromTopRight(self, child: child, top: top, right: right)
}
/**
:name: bottomLeft
*/
public func bottomLeft(child: UIView, bottom: CGFloat, left: CGFloat) {
Layout.alignFromBottomLeft(self, child: child, bottom: bottom, left: left)
}
/**
:name: bottomRight
*/
public func bottomRight(child: UIView, bottom: CGFloat, right: CGFloat) {
Layout.alignFromBottomRight(self, child: child, bottom: bottom, right: right)
}
}
//
// 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 MaterialViewController : UIViewController {
/**
:name: topLeft
*/
public func topLeft(child: UIView, top: CGFloat, left: CGFloat) {
Layout.alignFromTopLeft(view, child: child, top: top, left: left)
}
/**
:name: topRight
*/
public func topRight(child: UIView, top: CGFloat, right: CGFloat) {
Layout.alignFromTopRight(view, child: child, top: top, right: right)
}
/**
:name: bottomLeft
*/
public func bottomLeft(child: UIView, bottom: CGFloat, left: CGFloat) {
Layout.alignFromBottomLeft(view, child: child, bottom: bottom, left: left)
}
/**
:name: bottomRight
*/
public func bottomRight(child: UIView, bottom: CGFloat, right: CGFloat) {
Layout.alignFromBottomRight(view, child: child, bottom: bottom, right: right)
}
}
......@@ -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,11 +38,29 @@ public class RaisedButton : UIButton {
func initialize() {
color = UIColor.redColor()
backgroundColorView = UIView()
pulseColor = UIColor.whiteColor()
setTranslatesAutoresizingMaskIntoConstraints(false)
}
func setupContext(rect: CGRect) {
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
pulseTouches(touches)
}
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
shrink()
removePulse()
}
public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
shrink()
removePulse()
}
private func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
......@@ -61,31 +70,23 @@ public class RaisedButton : 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 = color
backgroundColorView.layer.masksToBounds = true
self.insertSubview(backgroundColorView, atIndex: 0)
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)
}
func applyShadow() {
private 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) {
pulseTouches(touches)
}
public override func touchesEnded(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()
......@@ -93,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
}
}
}
......
......@@ -9,19 +9,24 @@
import UIKit
public struct Roboto {
public static func lightWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Roboto-Light", size: size)!
if let light = UIFont(name: "Roboto-Light", size: size) {
return light
}
return UIFont.systemFontOfSize(size)
}
public static func mediumWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Roboto-Medium", size: size)!
if let light = UIFont(name: "Roboto-Medium", size: size) {
return light
}
return UIFont.systemFontOfSize(size)
}
public static func regularWithSize(size: CGFloat) -> UIFont {
var fonts = UIFont.fontNamesForFamilyName("Roboto")
println(fonts)
return UIFont(name: "Arial", size: size)!
if let light = UIFont(name: "Roboto-Regular", size: size) {
return light
}
return UIFont.systemFontOfSize(size)
}
}
bg.png

15 KB

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