Commit b1776925 by Daniel Dahan

Grid example working

parent 6541b23e
{
"images" : [
{
"idiom" : "universal",
"filename" : "CosmicMindInverted.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_alarm_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_alarm_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_alarm_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -33,8 +33,6 @@
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, ); }; };
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 */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
......@@ -134,8 +132,6 @@
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>"; };
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>"; };
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>"; };
......@@ -236,8 +232,6 @@
isa = PBXGroup;
children = (
9656CD0B1C6BD33700EBCEF1 /* Grid.swift */,
9656CD0E1C6BF28600EBCEF1 /* RowView.swift */,
9656CD0D1C6BF28600EBCEF1 /* ColumnView.swift */,
);
name = Grid;
sourceTree = "<group>";
......@@ -609,14 +603,12 @@
96D88C361C1328D800B91418 /* MaterialPulseView.swift in Sources */,
960B23301C383EAA00E96216 /* Material+UIImage+Network.swift in Sources */,
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */,
9656CD101C6BF28600EBCEF1 /* RowView.swift in Sources */,
96D88C2D1C1328D800B91418 /* MaterialDepth.swift in Sources */,
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */,
96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */,
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
9656CD0F1C6BF28600EBCEF1 /* ColumnView.swift in Sources */,
96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */,
96D88C301C1328D800B91418 /* MaterialEdgeInsetPreset.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
......@@ -30,19 +30,19 @@
import UIKit
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 Cell : Int {
case Cell1 = 1
case Cell2 = 2
case Cell3 = 3
case Cell4 = 4
case Cell5 = 5
case Cell6 = 6
case Cell7 = 7
case Cell8 = 8
case Cell9 = 9
case Cell10 = 10
case Cell11 = 11
case Cell12 = 12
}
public enum GridLayout {
......@@ -52,29 +52,22 @@ public enum GridLayout {
public protocol GridCell {
/// Grid column size.
var column: GridSize { get set }
var column: Cell { get set }
/// Grid row size.
var row: GridSize { get set }
var row: Cell { get set }
}
public class Grid {
/// The size of the grid.
public var size: CGSize = CGSizeZero {
/// The row size.
public var row: Cell {
didSet {
reloadLayout()
}
}
/// The column size.
public var column: GridSize {
didSet {
reloadLayout()
}
}
/// The row size.
public var row: GridSize {
public var column: Cell {
didSet {
reloadLayout()
}
......@@ -115,7 +108,7 @@ public class Grid {
}
}
public init(row: GridSize = .Grid12, column: GridSize = .Grid12, spacing: CGFloat = 0) {
public init(row: Cell = .Cell12, column: Cell = .Cell12, spacing: CGFloat = 0) {
self.row = row
self.column = column
self.spacing = spacing
......@@ -123,36 +116,55 @@ public class Grid {
/// 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.grid.column.rawValue
let r: Int = view.grid.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)
if let sv: UIView = view.superview {
let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right + spacing) / CGFloat(column.rawValue)
let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom + spacing) / CGFloat(row.rawValue)
let c: Int = view.grid.column.rawValue
let r: Int = view.grid.row.rawValue
if .Horizontal == layout {
// View height.
let vh: CGFloat = sv.bounds.height - contentInset.top - contentInset.bottom
// View left.
let vl: CGFloat = CGFloat(i + n) * w + contentInset.left
// View width.
let vw: CGFloat = (w * CGFloat(c)) - spacing
if 0 == i {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
} else if l == i {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
} else {
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
}
} else if .Vertical == layout {
// View width.
let vw: CGFloat = sv.bounds.width - contentInset.left - contentInset.right
// View top.
let vt: CGFloat = CGFloat(i + m) * h + contentInset.top
// View height.
let vh: CGFloat = (h * CGFloat(r)) - spacing
if 0 == i {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
} else if l == i {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
} else {
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
}
}
n += c - 1
m += r - 1
}
n += c - 1
m += r - 1
}
}
}
......
/*
* 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