Commit 1e61905c by Daniel Dahan

working internal grid

parent 0ae3220c
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
96442ADB1C28EEFA00C3C574 /* TextField.swift in Headers */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96442ADB1C28EEFA00C3C574 /* TextField.swift in Headers */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; }; 96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; };
96442ADF1C28EF3E00C3C574 /* MaterialTableViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96442ADF1C28EF3E00C3C574 /* MaterialTableViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
965C58BC1C6B8D2B00CFB4E1 /* GridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965C58BB1C6B8D2B00CFB4E1 /* GridView.swift */; }; 9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */; };
9656CD0F1C6BF28600EBCEF1 /* ColumnView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */; };
9656CD101C6BF28600EBCEF1 /* RowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656CD0E1C6BF28600EBCEF1 /* RowView.swift */; };
966F57B81C226D75009185B7 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; }; 966F57B81C226D75009185B7 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
...@@ -131,7 +133,9 @@ ...@@ -131,7 +133,9 @@
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTableViewCell.swift; sourceTree = "<group>"; }; 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTableViewCell.swift; sourceTree = "<group>"; };
965C58BB1C6B8D2B00CFB4E1 /* GridView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GridView.swift; sourceTree = "<group>"; }; 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = "<group>"; };
9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColumnView.swift; sourceTree = "<group>"; };
9656CD0E1C6BF28600EBCEF1 /* RowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowView.swift; sourceTree = "<group>"; };
966F57B71C226D75009185B7 /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; }; 966F57B71C226D75009185B7 /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; }; 96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
...@@ -231,7 +235,9 @@ ...@@ -231,7 +235,9 @@
965C58BD1C6B8D3300CFB4E1 /* Grid */ = { 965C58BD1C6B8D3300CFB4E1 /* Grid */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
965C58BB1C6B8D2B00CFB4E1 /* GridView.swift */, 9656CD0B1C6BD33700EBCEF1 /* Grid.swift */,
9656CD0E1C6BF28600EBCEF1 /* RowView.swift */,
9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */,
); );
name = Grid; name = Grid;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -585,13 +591,13 @@ ...@@ -585,13 +591,13 @@
96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */, 96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */,
96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */, 96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */,
96D88C2A1C1328D800B91418 /* MaterialBorder.swift in Sources */, 96D88C2A1C1328D800B91418 /* MaterialBorder.swift in Sources */,
9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */,
960B23461C38480E00E96216 /* Text.swift in Sources */, 960B23461C38480E00E96216 /* Text.swift in Sources */,
96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */, 96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */,
96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */, 96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */,
96D88C231C1328D800B91418 /* FlatButton.swift in Sources */, 96D88C231C1328D800B91418 /* FlatButton.swift in Sources */,
966F57B81C226D75009185B7 /* TextField.swift in Sources */, 966F57B81C226D75009185B7 /* TextField.swift in Sources */,
96DBA7361C61198400844821 /* Material+UIImage+Color.swift in Sources */, 96DBA7361C61198400844821 /* Material+UIImage+Color.swift in Sources */,
965C58BC1C6B8D2B00CFB4E1 /* GridView.swift in Sources */,
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */, 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */,
96D88C3E1C1328D800B91418 /* NavigationBarView.swift in Sources */, 96D88C3E1C1328D800B91418 /* NavigationBarView.swift in Sources */,
96D88C221C1328D800B91418 /* FabButton.swift in Sources */, 96D88C221C1328D800B91418 /* FabButton.swift in Sources */,
...@@ -603,12 +609,14 @@ ...@@ -603,12 +609,14 @@
96D88C361C1328D800B91418 /* MaterialPulseView.swift in Sources */, 96D88C361C1328D800B91418 /* MaterialPulseView.swift in Sources */,
960B23301C383EAA00E96216 /* Material+UIImage+Network.swift in Sources */, 960B23301C383EAA00E96216 /* Material+UIImage+Network.swift in Sources */,
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */, 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */,
9656CD101C6BF28600EBCEF1 /* RowView.swift in Sources */,
96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */, 96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */,
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */, 96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */, 96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */, 960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */,
96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */, 96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */,
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */, 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
9656CD0F1C6BF28600EBCEF1 /* ColumnView.swift in Sources */,
96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */, 96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */,
96D88C301C1328D800B91418 /* MaterialEdgeInsetPreset.swift in Sources */, 96D88C301C1328D800B91418 /* MaterialEdgeInsetPreset.swift in Sources */,
96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */, 96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */,
......
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public class ColumnView : MaterialView {
// internal var grid: Grid
//
// public required init?(coder aDecoder: NSCoder) {
// grid = Grid()
// super.init(coder: aDecoder)
// }
//
// public override init(frame: CGRect) {
// grid = Grid()
// super.init(frame: frame)
// }
//
// public convenience init() {
// self.init(frame: CGRectNull)
// }
//
// public override func layoutSubviews() {
// super.layoutSubviews()
// grid.reloadLayout()
// }
}
\ No newline at end of file
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Foundation
func associatedObject<ValueType: AnyObject>(
base: AnyObject,
key: UnsafePointer<UInt8>,
initialiser: () -> ValueType)
-> ValueType {
if let associated = objc_getAssociatedObject(base, key)
as? ValueType { return associated }
let associated = initialiser()
objc_setAssociatedObject(base, key, associated,
.OBJC_ASSOCIATION_RETAIN)
return associated
}
func associateObject<ValueType: AnyObject>(
base: AnyObject,
key: UnsafePointer<UInt8>,
value: ValueType) {
objc_setAssociatedObject(base, key, value,
.OBJC_ASSOCIATION_RETAIN)
}
public enum GridSize : Int {
case Grid1 = 1
case Grid2 = 2
case Grid3 = 3
case Grid4 = 4
case Grid5 = 5
case Grid6 = 6
case Grid7 = 7
case Grid8 = 8
case Grid9 = 9
case Grid10 = 10
case Grid11 = 11
case Grid12 = 12
}
public enum GridLayout {
case Horizontal
case Vertical
}
private var gridKey: UInt8 = 0
public extension UIView {
public var grid: Grid {
get {
return associatedObject(self, key: &gridKey) { return Grid() }
}
set(value) {
associateObject(self, key: &gridKey, value: value)
}
}
public var column: GridSize {
get {
return grid.column
}
set(value) {
grid.column = value
}
}
public var row: GridSize {
get {
return grid.row
}
set(value) {
grid.row = value
}
}
public var size: CGSize {
get {
return grid.size
}
set(value) {
grid.size = value
}
}
public var spacing: CGFloat {
get {
return grid.spacing
}
set(value) {
grid.spacing = value
}
}
public var views: Array<UIView>? {
get {
return grid.views
}
set(value) {
grid.views = value
}
}
}
public protocol GridCell {
/// Grid column size.
var column: GridSize { get set }
/// Grid row size.
var row: GridSize { get set }
}
public class Grid {
/// The size of the grid.
public var size: CGSize = CGSizeZero {
didSet {
reloadLayout()
}
}
/// The column size.
public var column: GridSize {
didSet {
reloadLayout()
}
}
/// The row size.
public var row: GridSize {
didSet {
reloadLayout()
}
}
/// Preset inset value for grid.
public var contentInsetPreset: MaterialEdgeInsetPreset = .None {
didSet {
contentInset = MaterialEdgeInsetPresetToValue(contentInsetPreset)
}
}
/// Insets value for grid.
public var contentInset: UIEdgeInsets = MaterialEdgeInsetPresetToValue(.None) {
didSet {
reloadLayout()
}
}
/// The space between grid columns.
public var spacing: CGFloat {
didSet {
reloadLayout()
}
}
/// The direction in which the animation opens the menu.
public var layout: GridLayout = .Horizontal {
didSet {
reloadLayout()
}
}
/// An Array of UIButtons.
public var views: Array<UIView>? {
didSet {
reloadLayout()
}
}
public init(row: GridSize = .Grid12, column: GridSize = .Grid12, spacing: CGFloat = 0) {
self.row = row
self.column = column
self.spacing = spacing
}
/// Reload the button layout.
public func reloadLayout() {
let gc: Int = column.rawValue
let gr: Int = row.rawValue
let w: CGFloat = (size.width - contentInset.left - contentInset.right) / CGFloat(gc)
let h: CGFloat = (size.height - contentInset.top - contentInset.bottom - spacing) / CGFloat(gr)
if let v: Array<UIView> = views {
var n: Int = 0
var m: Int = 0
for var i: Int = 0, l: Int = v.count - 1; i <= l; ++i {
let view: UIView = v[i]
let c: Int = view.column.rawValue
let r: Int = view.row.rawValue
if .Horizontal == layout {
if 0 == i {
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.left, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom)
} else if l == i {
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.left + spacing, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom)
} else {
view.frame = CGRectMake(CGFloat(i + n) * w + contentInset.right, contentInset.top, (w * CGFloat(c)) - spacing, (0 < size.height ? size.height : view.intrinsicContentSize().height) - contentInset.top - contentInset.bottom)
}
} else {
if 0 == i {
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing)
} else if l == i {
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing)
} else {
view.frame = CGRectMake(contentInset.left, CGFloat(i + m) * h + contentInset.top + spacing, (0 < size.width ? size.width : view.intrinsicContentSize().width) - contentInset.left - contentInset.right, (h * CGFloat(r)) - spacing)
}
}
n += c - 1
m += r - 1
}
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public enum Grid : Int {
case Grid1 = 1
case Grid2 = 2
case Grid3 = 3
case Grid4 = 4
case Grid5 = 5
case Grid6 = 6
case Grid7 = 7
case Grid8 = 8
case Grid9 = 9
case Grid10 = 10
case Grid11 = 11
case Grid12 = 12
}
public enum GridLayout {
case Horizontal
case Vertical
}
public protocol GridCell {
/// Grid spacing.
var grid: Grid { get set }
}
public class GridView : MaterialView {
/// A single height for all views.
public var unifiedHeight: CGFloat = 0 {
didSet {
reloadLayout()
}
}
/// The grid size.
public override var grid: Grid {
didSet {
reloadLayout()
}
}
/// The space between grid columns.
public var spacing: CGFloat {
didSet {
reloadLayout()
}
}
/// The direction in which the animation opens the menu.
public var layout: GridLayout = .Horizontal {
didSet {
reloadLayout()
}
}
/// An Array of UIButtons.
public var views: Array<GridCell>? {
didSet {
reloadLayout()
}
}
public convenience init() {
self.init(frame: CGRectNull)
}
public required init?(coder aDecoder: NSCoder) {
spacing = 0
super.init(coder: aDecoder)
grid = .Grid12
}
public override init(frame: CGRect) {
spacing = 0
super.init(frame: frame)
grid = .Grid12
}
public override func layoutSubviews() {
super.layoutSubviews()
reloadLayout()
}
/// Reload the button layout.
public func reloadLayout() {
for v in subviews {
v.removeFromSuperview()
}
let g: Int = grid.rawValue
let w: CGFloat = (width - spacing) / CGFloat(g)
let h: CGFloat = (height - spacing) / CGFloat(g)
if let v: Array<GridCell> = views {
var n: Int = 0
for var i: Int = 0, l: Int = v.count; i < l; ++i {
let cell: GridCell = v[i]
let view: UIView = cell as! UIView
let m: Int = cell.grid.rawValue
if .Horizontal == layout {
view.frame = CGRectMake(CGFloat(i + n) * w + spacing, 0, (w * CGFloat(m)) - spacing, 0 < unifiedHeight ? unifiedHeight : view.intrinsicContentSize().height)
} else {
view.frame = CGRectMake(0, CGFloat(i + n) * h + spacing, view.intrinsicContentSize().width, (h * CGFloat(m)) - spacing)
}
view.removeFromSuperview()
addSubview(view)
n += m - 1
}
}
}
}
\ No newline at end of file
...@@ -31,10 +31,7 @@ ...@@ -31,10 +31,7 @@
import UIKit import UIKit
@objc(MaterialButton) @objc(MaterialButton)
public class MaterialButton : UIButton, GridCell { public class MaterialButton : UIButton {
/// Grid space.
public var grid: Grid = .Grid1
/** /**
A CAShapeLayer used to manage elements that would be affected by A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this the clipToBounds property of the backing layer. For example, this
......
...@@ -30,7 +30,122 @@ ...@@ -30,7 +30,122 @@
import UIKit import UIKit
public class MaterialLabel : UILabel, GridCell { public class MaterialLabel : UILabel {
/// Grid space. /**
public var grid: Grid = .Grid1 :name: layerClass
*/
public override class func layerClass() -> AnyClass {
return MaterialTextLayer.self
}
/**
:name: textLayer
*/
public var textLayer: MaterialTextLayer {
return layer as! MaterialTextLayer
}
/**
:name: text
*/
public override var text: String? {
didSet {
textLayer.text = text
}
}
/**
:name: textColor
*/
public override var textColor: UIColor? {
didSet {
textLayer.textColor = textColor
}
}
/**
:name: font
*/
public override var font: UIFont! {
didSet {
textLayer.fontType = font
}
}
/**
:name: textAlignment
*/
public override var textAlignment: NSTextAlignment {
didSet {
textLayer.textAlignment = textAlignment
}
}
/**
:name: wrapped
*/
public var wrapped: Bool {
didSet {
textLayer.wrapped = wrapped
}
}
/**
:name: contentsScale
*/
public var contentsScale: CGFloat {
didSet {
textLayer.contentsScale = contentsScale
}
}
/**
:name: lineBreakMode
*/
public override var lineBreakMode: NSLineBreakMode {
didSet {
textLayer.lineBreakMode = lineBreakMode
}
}
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
wrapped = true
contentsScale = UIScreen.mainScreen().scale
super.init(coder: aDecoder)
}
/**
:name: init
*/
public override init(frame: CGRect) {
wrapped = true
contentsScale = UIScreen.mainScreen().scale
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectNull)
prepareView()
}
/**
:name: stringSize
*/
public func stringSize(constrainedToWidth width: Double) -> CGSize {
return textLayer.stringSize(constrainedToWidth: width)
}
/**
:name: prepareView
*/
public func prepareView() {
textAlignment = .Left
}
} }
\ No newline at end of file
...@@ -31,10 +31,7 @@ ...@@ -31,10 +31,7 @@
import UIKit import UIKit
@objc(MaterialView) @objc(MaterialView)
public class MaterialView : UIView, GridCell { public class MaterialView : UIView {
/// Grid space.
public var grid: Grid = .Grid1
/** /**
A CAShapeLayer used to manage elements that would be affected by A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this the clipToBounds property of the backing layer. For example, this
......
/*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public class RowView : MaterialView {
// internal var grid: Grid
//
// public required init?(coder aDecoder: NSCoder) {
// grid = Grid()
// super.init(coder: aDecoder)
// }
//
// public override init(frame: CGRect) {
// grid = Grid()
// super.init(frame: frame)
// }
//
// public convenience init() {
// self.init(frame: CGRectNull)
// }
//
// public override func layoutSubviews() {
// super.layoutSubviews()
// grid.reloadLayout()
// }
}
\ No newline at end of file
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