Commit 72c0ad8a by adamdahan

Added new class Basic Card, small clean up for other component files and the…

Added new class Basic Card, small clean up for other component files and the addition of a font class Roboto with font files.
parent 5e8d2dec
......@@ -13,7 +13,6 @@
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638325F1B88E5BF0015F710 /* CapturePreview.swift */; };
9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832601B88E5BF0015F710 /* FabButton.swift */; };
9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832611B88E5BF0015F710 /* FlatButton.swift */; };
9638326E1B88E5BF0015F710 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; };
963832701B88E5BF0015F710 /* RaisedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832651B88E5BF0015F710 /* RaisedButton.swift */; };
963832711B88E5BF0015F710 /* Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832661B88E5BF0015F710 /* Text.swift */; };
963832721B88E5BF0015F710 /* TextStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832671B88E5BF0015F710 /* TextStorage.swift */; };
......@@ -28,6 +27,14 @@
963832851B89070E0015F710 /* CapturePreview.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9638325F1B88E5BF0015F710 /* CapturePreview.swift */; settings = {ATTRIBUTES = (Public, ); }; };
963832881B8908180015F710 /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; };
963832891B89097D0015F710 /* Layout.swift in Headers */ = {isa = PBXBuildFile; fileRef = 963832871B8908180015F710 /* Layout.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9A94D0F91B895C8C00F586A5 /* Roboto.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9AAC38531B89559900FE6B2D /* Roboto.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 963832631B88E5BF0015F710 /* LICENSE */; };
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 */; };
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, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -56,6 +63,11 @@
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>"; };
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>"; };
9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Medium.ttf"; sourceTree = "<group>"; };
9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Regular.ttf"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -98,11 +110,13 @@
963832521B88E30F0015F710 /* Source */ = {
isa = PBXGroup;
children = (
9638325C1B88E3420015F710 /* Supporting Files */,
963832631B88E5BF0015F710 /* LICENSE */,
9638325C1B88E3420015F710 /* Supporting Files */,
9AAC38521B89553800FE6B2D /* Font */,
963832861B8907FE0015F710 /* Layout */,
963832761B88E8990015F710 /* Text */,
963832751B88E87B0015F710 /* Button */,
9AAC384B1B89524E00FE6B2D /* Card */,
963832741B88E86B0015F710 /* Capture */,
);
path = Source;
......@@ -170,6 +184,25 @@
name = Layout;
sourceTree = "<group>";
};
9AAC384B1B89524E00FE6B2D /* Card */ = {
isa = PBXGroup;
children = (
9AAC384C1B89528900FE6B2D /* BasicCard.swift */,
);
name = Card;
sourceTree = "<group>";
};
9AAC38521B89553800FE6B2D /* Font */ = {
isa = PBXGroup;
children = (
9AAC38591B8956E300FE6B2D /* Roboto-Regular.ttf */,
9AAC38571B8956CF00FE6B2D /* Roboto-Medium.ttf */,
9AAC38551B8956C500FE6B2D /* Roboto-Light.ttf */,
9AAC38531B89559900FE6B2D /* Roboto.swift */,
);
name = Font;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
......@@ -177,6 +210,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
9AAC385F1B8957A200FE6B2D /* BasicCard.swift in Headers */,
9638327E1B89070E0015F710 /* Text.swift in Headers */,
9638327F1B89070E0015F710 /* TextStorage.swift in Headers */,
963832801B89070E0015F710 /* TextView.swift in Headers */,
......@@ -184,6 +218,7 @@
963832821B89070E0015F710 /* FlatButton.swift in Headers */,
963832831B89070E0015F710 /* RaisedButton.swift in Headers */,
963832841B89070E0015F710 /* Capture.swift in Headers */,
9A94D0F91B895C8C00F586A5 /* Roboto.swift in Headers */,
963832851B89070E0015F710 /* CapturePreview.swift in Headers */,
963832891B89097D0015F710 /* Layout.swift in Headers */,
);
......@@ -268,7 +303,10 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9638326E1B88E5BF0015F710 /* LICENSE in Resources */,
9A94D0FA1B895EA500F586A5 /* LICENSE in Resources */,
9A94D0FB1B895EA500F586A5 /* Roboto-Regular.ttf in Resources */,
9A94D0FC1B895EA500F586A5 /* Roboto-Medium.ttf in Resources */,
9A94D0FD1B895EA500F586A5 /* Roboto-Light.ttf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -291,7 +329,9 @@
9638326C1B88E5BF0015F710 /* FlatButton.swift in Sources */,
963832711B88E5BF0015F710 /* Text.swift in Sources */,
9638326A1B88E5BF0015F710 /* CapturePreview.swift in Sources */,
9AAC38541B89559900FE6B2D /* Roboto.swift in Sources */,
963832881B8908180015F710 /* Layout.swift in Sources */,
9AAC384D1B89528900FE6B2D /* BasicCard.swift in Sources */,
963832731B88E5BF0015F710 /* TextView.swift in Sources */,
963832721B88E5BF0015F710 /* TextStorage.swift in Sources */,
963832701B88E5BF0015F710 /* RaisedButton.swift in Sources */,
......
//
// 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
import QuartzCore
public class BasicCard : UIView {
private var views: NSMutableDictionary = NSMutableDictionary()
public var cancelButton: FlatButton = FlatButton()
public var otherButton: FlatButton = FlatButton()
public var color: UIColor?
public var pulseColor: UIColor?
public var titleLabel: UILabel = UILabel()
public var detailTextLabel: UILabel = UILabel()
public var horizontalSeparator: UIView = UIView()
public var backgroundColorView: UIView?
public var pulseView: UIView?
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}
public required override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
func initialize() {
setupSelf()
setupLayer()
setupTitleLabel()
setupDetailTextLabel()
setupHorizontalLineSeparator()
setupButtons()
setupBackgroundColorView()
constrainSubviews()
}
func setupContext(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, UIColor.clearColor().CGColor)
CGContextFillRect(context, rect)
CGContextRestoreGState(context)
}
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)
}
func setupLayer() {
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOffset = CGSizeMake(0.5, 0.5)
self.layer.shadowRadius = 5.0
self.layer.shadowOpacity = 0.4
self.layer.cornerRadius = 2.0
}
func setupTitleLabel() {
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
titleLabel.font = Roboto.regularWithSize(22.0)
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "Card Title"
self.addSubview(titleLabel)
views.setObject(titleLabel, forKey: "titleLabel")
}
func setupDetailTextLabel() {
detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
detailTextLabel.font = Roboto.lightWithSize(16.0)
detailTextLabel.textColor = UIColor.whiteColor()
detailTextLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
detailTextLabel.numberOfLines = 0
detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
addSubview(detailTextLabel)
views.setObject(detailTextLabel, forKey: "detailTextLabel")
}
func setupHorizontalLineSeparator() {
horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
horizontalSeparator.backgroundColor = UIColor.whiteColor()
horizontalSeparator.alpha = 0.2
addSubview(horizontalSeparator)
views.setObject(horizontalSeparator, forKey: "line")
}
func setupButtons() {
setupCancelButton()
setupOtherButton()
}
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
addSubview(cancelButton)
views.setObject(cancelButton, forKey: "cancelButton")
}
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
addSubview(otherButton)
views.setObject(otherButton, forKey: "otherButton")
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func setupBackgroundColorView() {
backgroundColorView = UIView()
backgroundColorView!.setTranslatesAutoresizingMaskIntoConstraints(false)
backgroundColorView!.layer.cornerRadius = 2.0
backgroundColorView!.backgroundColor = color
backgroundColorView!.layer.masksToBounds = true
self.insertSubview(backgroundColorView!, atIndex: 0)
views.setObject(backgroundColorView!, forKey: "bgView")
}
func constrainSubviews() {
// Background
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]))
// 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]))
}
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) {
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)
}
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
}
}
}
......@@ -20,8 +20,8 @@ import UIKit
public class FlatButton : UIButton {
var textColor: UIColor?
var pulseColor: UIColor?
public var textColor: UIColor?
public var pulseColor: UIColor?
private var vLine: UIView = UIView()
private var hLine: UIView = UIView()
......
......@@ -22,5 +22,11 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
<key>UIAppFonts</key>
<array>
<string>Roboto-Medium.ttf</string>
<string>Roboto-Regular.ttf</string>
<string>Roboto-Light.ttf</string>
</array>
</dict>
</plist>
......@@ -20,8 +20,8 @@ import UIKit
public class RaisedButton : UIButton {
var color: UIColor?
var pulseColor: UIColor?
public var color: UIColor?
public var pulseColor: UIColor?
private var vLine: UIView = UIView()
private var hLine: UIView = UIView()
......
//
// Roboto.swift
// MaterialKit
//
// Created by Adam Dahan on 2015-08-22.
// Copyright (c) 2015 GraphKit Inc. All rights reserved.
//
import UIKit
public struct Roboto {
public static func lightWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Roboto-Light", size: size)!
}
public static func mediumWithSize(size: CGFloat) -> UIFont {
return UIFont(name: "Roboto-Medium", size: size)!
}
public static func regularWithSize(size: CGFloat) -> UIFont {
var fonts = UIFont.fontNamesForFamilyName("Roboto")
println(fonts)
return UIFont(name: "Arial", size: size)!
}
}
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