Commit 513e81ef by Daniel Dahan

added MaterialSpacing type for spacingPreset property.

parent 951f9b12
......@@ -61,12 +61,9 @@ class FeedViewController: UIViewController {
collectionView.dataSource = self
collectionView.delegate = self
collectionView.registerClass(BasicCollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.spacingPreset = .Spacing1
collectionView.contentInsetPreset = .Square1
if let v: BasicCollectionViewLayout = collectionView.collectionViewLayout as? BasicCollectionViewLayout {
v.spacing = 4
v.contentInset = UIEdgeInsetsMake(4, 4, 4, 4)
// v.scrollDirection = .Horizontal
}
view.addSubview(collectionView)
}
}
......@@ -75,18 +72,18 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves the items for the collectionView.
func items() -> Array<MaterialDataSourceItem> {
return [
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead"], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead"], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead"], width: 125, height: 125),
MaterialDataSourceItem(data: ["detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also..."], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting..."], width: 125, height: 125)
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], width: 125, height: 125),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], width: 125, height: 125)
]
}
......@@ -102,13 +99,48 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves a UICollectionViewCell.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let c: MaterialCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! MaterialCollectionViewCell
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.item]
c.backgroundColor = MaterialColor.white
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
if nil == data["title"] {
c.titleLabel = nil
} else if nil == c.titleLabel {
let titleLabel: UILabel = UILabel()
titleLabel.textColor = MaterialColor.blueGrey.darken4
titleLabel.backgroundColor = MaterialColor.clear
c.titleLabel = titleLabel
}
if nil == data["detail"] {
c.detailLabel = nil
} else if nil == c.detailLabel {
let detailLabel: UILabel = UILabel()
detailLabel.numberOfLines = 0
detailLabel.lineBreakMode = .ByTruncatingTail
detailLabel.font = RobotoFont.regularWithSize(12)
detailLabel.textColor = MaterialColor.blueGrey.darken4
detailLabel.backgroundColor = MaterialColor.clear
c.detailLabel = detailLabel
}
if nil == c.controlView {
c.controlView = ControlView()
c.controlView!.backgroundColor = nil
let date: UILabel = UILabel()
date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.lighten1
c.controlView?.contentView.addSubview(date)
c.controlView?.grid.views = [date]
}
c.titleLabel?.text = data["title"] as? String
c.detailLabel?.text = data["detail"] as? String
(c.controlView?.contentView.subviews.first as? UILabel)?.text = data["date"] as? String
c.reloadView()
}
return c
......
......@@ -66,6 +66,7 @@
96CC08991C80B74F0034FF84 /* BasicCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */; };
96CC089B1C80B82E0034FF84 /* BasicCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */; };
96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */; };
96CC08A01C80CB180034FF84 /* MaterialSpacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
......@@ -182,6 +183,7 @@
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; };
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionView.swift; sourceTree = "<group>"; };
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewLayout.swift; sourceTree = "<group>"; };
96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialSpacing.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>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
......@@ -350,17 +352,25 @@
96CC08891C7FEBE10034FF84 /* CollectionView */ = {
isa = PBXGroup;
children = (
96CC089E1C80BD550034FF84 /* Basic */,
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */,
96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */,
96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */,
96CC088E1C7FEC170034FF84 /* MaterialCollectionViewDelegate.swift */,
96CC088F1C7FEC170034FF84 /* MaterialCollectionViewLayout.swift */,
96CC08901C7FEC170034FF84 /* MaterialDataSourceItem.swift */,
);
name = CollectionView;
sourceTree = "<group>";
};
96CC089E1C80BD550034FF84 /* Basic */ = {
isa = PBXGroup;
children = (
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */,
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */,
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */,
);
name = CollectionView;
name = Basic;
sourceTree = "<group>";
};
96D88BF41C1328D800B91418 /* Sources */ = {
......@@ -437,6 +447,7 @@
96D88C061C1328D800B91418 /* MaterialGravity.swift */,
96D88C071C1328D800B91418 /* MaterialEdgeInset.swift */,
96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */,
96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */,
);
name = Type;
sourceTree = "<group>";
......@@ -758,6 +769,7 @@
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */,
96D88C301C1328D800B91418 /* MaterialEdgeInset.swift in Sources */,
96CC08A01C80CB180034FF84 /* MaterialSpacing.swift in Sources */,
96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */,
96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */,
960B23271C383E5500E96216 /* Material+String.swift in Sources */,
......
......@@ -51,6 +51,13 @@ public class ControlView : MaterialView {
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
grid.spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
......
......@@ -139,6 +139,13 @@ public class Grid {
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// The space between grid columnss.
public var spacing: CGFloat {
didSet {
......
......@@ -31,6 +31,52 @@
import UIKit
public class MaterialCollectionView : UICollectionView {
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value
}
}
public override var contentInset: UIEdgeInsets {
get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value
}
}
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection {
get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// Spacing between items.
public var spacing: CGFloat {
get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.spacing
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.spacing = value
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
......
......@@ -52,6 +52,13 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
......
......@@ -56,6 +56,13 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection = .Vertical
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// Spacing between items.
public var spacing: CGFloat = 0
......
......@@ -43,9 +43,7 @@ public enum MaterialRadius {
case Radius9
}
/**
:name: MaterialRadiusToValue
*/
/// Converts the MaterialRadius enum to a CGFloat value.
public func MaterialRadiusToValue(radius: MaterialRadius) -> CGFloat {
switch radius {
case .None:
......
/*
* Copyright (C) 2015 - 2016, 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 MaterialSpacing {
case None
case Spacing1
case Spacing2
case Spacing3
case Spacing4
case Spacing5
case Spacing6
case Spacing7
case Spacing8
case Spacing9
}
/// Converts the MaterialSpacing enum to a CGFloat value.
public func MaterialSpacingToValue(radius: MaterialSpacing) -> CGFloat {
switch radius {
case .None:
return 0
case .Spacing1:
return 4
case .Spacing2:
return 8
case .Spacing3:
return 16
case .Spacing4:
return 24
case .Spacing5:
return 32
case .Spacing6:
return 40
case .Spacing7:
return 48
case .Spacing8:
return 56
case .Spacing9:
return 64
}
}
......@@ -48,6 +48,13 @@ public class Menu {
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// The space between views.
public var spacing: CGFloat {
didSet {
......
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