Commit 1ef54bde by Daniel Dahan

added base button class

parent dd2e3d5a
......@@ -14,6 +14,8 @@
65BDD14F1BB5EE4A006F7F2B /* MaterialGravity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD14E1BB5EE4A006F7F2B /* MaterialGravity.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1511BB6EE7C006F7F2B /* RobotoFont.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1541BB6F473006F7F2B /* MaterialShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1531BB6F473006F7F2B /* MaterialShadow.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1571BB6FC82006F7F2B /* MaterialButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1561BB6FC82006F7F2B /* MaterialButton.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1581BB6FE3E006F7F2B /* FlatButton.swift */; settings = {ASSET_TAGS = (); }; };
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */; };
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */; };
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; };
......@@ -44,6 +46,8 @@
65BDD14E1BB5EE4A006F7F2B /* MaterialGravity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialGravity.swift; sourceTree = "<group>"; };
65BDD1511BB6EE7C006F7F2B /* RobotoFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RobotoFont.swift; sourceTree = "<group>"; };
65BDD1531BB6F473006F7F2B /* MaterialShadow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialShadow.swift; sourceTree = "<group>"; };
65BDD1561BB6FC82006F7F2B /* MaterialButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialButton.swift; sourceTree = "<group>"; };
65BDD1581BB6FE3E006F7F2B /* FlatButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlatButton.swift; sourceTree = "<group>"; };
65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Bold.ttf"; sourceTree = "<group>"; };
65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarView.swift; sourceTree = "<group>"; };
......@@ -99,6 +103,15 @@
name = Roboto;
sourceTree = "<group>";
};
65BDD1551BB6FC60006F7F2B /* Button */ = {
isa = PBXGroup;
children = (
65BDD1561BB6FC82006F7F2B /* MaterialButton.swift */,
65BDD1581BB6FE3E006F7F2B /* FlatButton.swift */,
);
name = Button;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
isa = PBXGroup;
children = (
......@@ -125,6 +138,7 @@
96B57D4C1B90AF6A00DE7BBB /* Theme */,
9AAC38521B89553800FE6B2D /* Font */,
65B965851B8BEEB00055B139 /* View */,
65BDD1551BB6FC60006F7F2B /* Button */,
);
path = Source;
sourceTree = "<group>";
......@@ -291,9 +305,11 @@
files = (
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */,
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */,
65BDD14F1BB5EE4A006F7F2B /* MaterialGravity.swift in Sources */,
65BDD1541BB6F473006F7F2B /* MaterialShadow.swift in Sources */,
65BDD1571BB6FC82006F7F2B /* MaterialButton.swift in Sources */,
65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */,
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */,
65BDD14D1BB5ED9F006F7F2B /* MaterialTheme.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
public class FlatButton : MaterialButton {
//
// :name: prepareView
//
internal override func prepareView() {
super.prepareView()
setTitleColor(MaterialTheme.button.flat.titleLabelColorForNormalState, forState: .Normal)
titleLabel!.font = MaterialTheme.button.flat.titleLabelFont
backgroundColor = MaterialColor.red.base //MaterialTheme.button.flat.backgroudColor
// contentEdgeInsets = UIEdgeInsetsMake(8, 12, 8, 12)
}
//
// :name: prepareLayer
//
internal override func prepareLayer() {
super.prepareLayer()
shadow = MaterialTheme.button.flat.shadow
shadowColor = MaterialTheme.button.flat.shadowColor
zPosition = MaterialTheme.button.flat.zPosition
masksToBounds = MaterialTheme.button.flat.masksToBounds
}
}
\ No newline at end of file
//
// 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 {
/**
:name: backgroundColor
*/
public override var backgroundColor: UIColor? {
get {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!)
}
set(value) {
layer.backgroundColor = value?.CGColor
}
}
/**
:name: x
*/
public var x: CGFloat! {
didSet {
layer.bounds.origin.x = x
}
}
/**
:name: y
*/
public var y: CGFloat! {
didSet {
layer.bounds.origin = CGPointMake(x, y)
}
}
/**
:name: width
*/
public var width: CGFloat! {
didSet {
layer.bounds.size.width = width
}
}
/**
:name: height
*/
public var height: CGFloat! {
didSet {
layer.bounds.size.height = height
}
}
/**
:name: shadowColor
*/
public var shadowColor: UIColor! {
didSet {
layer.shadowColor = shadowColor.CGColor
}
}
/**
:name: shadowOffset
*/
public var shadowOffset: CGSize! {
didSet {
layer.shadowOffset = shadowOffset
}
}
/**
:name: shadowOpacity
*/
public var shadowOpacity: Float! {
didSet {
layer.shadowOpacity = shadowOpacity
}
}
/**
:name: shadowRadius
*/
public var shadowRadius: CGFloat! {
didSet {
layer.shadowRadius = shadowRadius
}
}
/**
:name: masksToBounds
*/
public var masksToBounds: Bool! {
didSet {
layer.masksToBounds = masksToBounds
}
}
/**
:name: shadow
*/
public var shadow: MaterialShadow! {
didSet {
let value: (offset: CGSize, opacity: Float, radius: CGFloat) = MaterialShadowToValues(shadow)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
}
}
/**
:name: zPosition
*/
public var zPosition: CGFloat! {
didSet {
layer.zPosition = zPosition
}
}
/**
:name: pulseColor
*/
public var pulseColor: UIColor? = MaterialColor.white
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
prepareLayer()
prepareBounds()
}
public convenience init() {
self.init(frame: CGRectMake(0, 0, 100, 100))
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
}
/**
:name: touchesEnded
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
}
/**
:name: touchesCancelled
*/
public override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
}
//
// :name: prepareView
//
internal func prepareView() {
userInteractionEnabled = MaterialTheme.button.userInteractionEnabled
}
//
// :name: prepareBounds
//
internal func prepareBounds() {
x = frame.origin.x
y = frame.origin.y
width = frame.size.width
height = frame.size.height
}
//
// :name: prepareLayer
//
internal func prepareLayer() {
}
}
\ No newline at end of file
......@@ -21,6 +21,11 @@ import UIKit
public struct MaterialTheme {
public struct view {}
public struct navigation {}
public struct button {
public struct fab {}
public struct flat {}
public struct raised {}
}
}
// view
......@@ -47,6 +52,9 @@ public extension MaterialTheme.view {
public static let contentsCenter: CGRect = CGRectMake(0, 0, 1, 1)
public static let contentsScale: CGFloat = UIScreen.mainScreen().scale
public static let contentsGravity: MaterialGravity = .ResizeAspectFill
// position
public static let zPosition: CGFloat = 0
}
// navigation
......@@ -74,5 +82,59 @@ public extension MaterialTheme.navigation {
public static let contentsCenter: CGRect = MaterialTheme.view.contentsCenter
public static let contentsScale: CGFloat = MaterialTheme.view.contentsScale
public static let contentsGravity: MaterialGravity = MaterialTheme.view.contentsGravity
// position
public static let zPosition: CGFloat = 100
}
// button
public extension MaterialTheme.button {
// shadow
public static let shadow: MaterialShadow = .Depth0
public static let shadowColor: UIColor = MaterialTheme.view.shadowColor
public static let masksToBounds: Bool = MaterialTheme.view.masksToBounds
// color
public static let backgroudColor: UIColor = MaterialColor.clear
public static let titleLabelColorForNormalState: UIColor = MaterialColor.blueGrey.darken4
// interaction
public static let userInteractionEnabled: Bool = true
// position
public static let zPosition: CGFloat = 200
// font
public static let titleLabelFont: UIFont = RobotoFont.regular
}
// button.flat
public extension MaterialTheme.button.flat {
// shadow
public static let shadow: MaterialShadow = MaterialTheme.button.shadow
public static let shadowColor: UIColor = MaterialTheme.button.shadowColor
public static let masksToBounds: Bool = MaterialTheme.button.masksToBounds
// color
public static let backgroudColor: UIColor = MaterialTheme.button.backgroudColor
public static let titleLabelColorForNormalState: UIColor = MaterialTheme.button.titleLabelColorForNormalState
// interaction
public static let userInteractionEnabled: Bool = MaterialTheme.button.userInteractionEnabled
// position
public static let zPosition: CGFloat = MaterialTheme.button.zPosition
// font
public static let titleLabelFont: UIFont = RobotoFont.regular
}
// button.fab
public extension MaterialTheme.button.fab {
}
// button.raised
public extension MaterialTheme.button.raised {
}
......@@ -170,6 +170,15 @@ public class MaterialView: UIView {
}
/**
:name: zPosition
*/
public var zPosition: CGFloat! {
didSet {
layer.zPosition = zPosition
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
......@@ -191,22 +200,19 @@ public class MaterialView: UIView {
*/
public convenience init() {
self.init(frame: CGRectMake(MaterialTheme.view.x, MaterialTheme.view.y, MaterialTheme.view.width, MaterialTheme.view.height))
prepareView()
prepareLayer()
prepareBounds()
}
/**
:name: prepareView
*/
//
// :name: prepareView
//
internal func prepareView() {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroudColor
}
/**
:name: prepareBounds
*/
//
// :name: prepareBounds
//
internal func prepareBounds() {
x = frame.origin.x
y = frame.origin.y
......@@ -214,9 +220,9 @@ public class MaterialView: UIView {
height = frame.size.height
}
/**
:name: prepareLayer
*/
//
// :name: prepareLayer
//
internal func prepareLayer() {
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
......@@ -224,6 +230,7 @@ public class MaterialView: UIView {
contentsGravity = MaterialTheme.view.contentsGravity
shadow = MaterialTheme.view.shadow
shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition
masksToBounds = MaterialTheme.view.masksToBounds
}
}
......
......@@ -33,30 +33,30 @@ public class NavigationBarView: MaterialView {
*/
public convenience init() {
self.init(frame: CGRectMake(MaterialTheme.navigation.x, MaterialTheme.navigation.y, MaterialTheme.navigation.width, MaterialTheme.navigation.height))
prepareView()
prepareLayer()
prepareBounds()
}
/**
:name: prepareView
*/
//
// :name: prepareView
//
internal override func prepareView() {
super.prepareView()
userInteractionEnabled = MaterialTheme.navigation.userInteractionEnabled
backgroundColor = MaterialTheme.navigation.backgroudColor
lightContentStatusBar = MaterialTheme.navigation.lightContentStatusBar
}
/**
:name: prepareLayer
*/
//
// :name: prepareLayer
//
internal override func prepareLayer() {
super.prepareLayer()
contentsRect = MaterialTheme.navigation.contentsRect
contentsCenter = MaterialTheme.navigation.contentsCenter
contentsScale = MaterialTheme.navigation.contentsScale
contentsGravity = MaterialTheme.navigation.contentsGravity
shadow = MaterialTheme.navigation.shadow
shadowColor = MaterialTheme.navigation.shadowColor
zPosition = MaterialTheme.navigation.zPosition
masksToBounds = MaterialTheme.navigation.masksToBounds
}
}
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