Commit 951f9b12 by Daniel Dahan

added BasicCollectionView

parent ad0295bc
......@@ -32,7 +32,7 @@ import UIKit
import Material
class FeedViewController: UIViewController {
private var collectionView: MaterialCollectionView = MaterialCollectionView(frame: CGRectNull)
private var collectionView: BasicCollectionView = BasicCollectionView()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -62,10 +62,10 @@ class FeedViewController: UIViewController {
collectionView.delegate = self
collectionView.registerClass(BasicCollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
if let v: MaterialCollectionViewLayout = collectionView.collectionViewLayout as? MaterialCollectionViewLayout {
if let v: BasicCollectionViewLayout = collectionView.collectionViewLayout as? BasicCollectionViewLayout {
v.spacing = 4
v.contentInset = UIEdgeInsetsMake(4, 4, 4, 4)
// v.scrollDirection = .Horizontal
// v.scrollDirection = .Horizontal
}
view.addSubview(collectionView)
}
......@@ -73,8 +73,8 @@ class FeedViewController: UIViewController {
extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves the items for the collectionView.
func items() -> Array<Array<MaterialDataSourceItem>> {
return [[
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),
......@@ -87,62 +87,28 @@ extension FeedViewController: MaterialCollectionViewDataSource {
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)
]]
]
}
/// Number of sections.
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return items().count
return 1
}
/// Number of cells in each section.
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items()[section].count
return items().count
}
/// Retrieves a UICollectionViewCell.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.section][indexPath.item]
let c: MaterialCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! MaterialCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.item]
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
if nil == data["title"] {
c.titleLabel = nil
} else if nil == c.titleLabel {
c.titleLabel = UILabel()
c.titleLabel?.textColor = MaterialColor.blueGrey.darken4
c.titleLabel?.backgroundColor = MaterialColor.clear
}
c.backgroundColor = MaterialColor.white
if nil == data["detail"] {
c.detailView = nil
} else if nil == c.detailView {
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.detailView = detailLabel
}
if nil == c.controlView {
c.controlView = ControlView()
c.controlView!.backgroundColor = nil
let date: UILabel = UILabel()
date.text = "Monday 6, 2016"
date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.lighten1
c.controlView!.contentView.addSubview(date)
c.controlView!.contentView.grid.views = [date]
}
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
c.titleLabel?.text = data["title"] as? String
(c.detailView as? UILabel)?.text = data["detail"] as? String
c.reloadView()
}
return c
......
......@@ -57,13 +57,15 @@
96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC083D1C7CF9D40034FF84 /* StatusBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; };
96CC083E1C7CFF2A0034FF84 /* StatusBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC08911C7FEC170034FF84 /* BasicCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088A1C7FEC170034FF84 /* BasicCollectionViewCell.swift */; };
96CC08921C7FEC170034FF84 /* MaterialCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */; };
96CC08931C7FEC170034FF84 /* MaterialCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */; };
96CC08941C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */; };
96CC08951C7FEC170034FF84 /* MaterialCollectionViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088E1C7FEC170034FF84 /* MaterialCollectionViewDelegate.swift */; };
96CC08961C7FEC170034FF84 /* MaterialCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC088F1C7FEC170034FF84 /* MaterialCollectionViewLayout.swift */; };
96CC08971C7FEC170034FF84 /* MaterialDataSourceItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08901C7FEC170034FF84 /* MaterialDataSourceItem.swift */; };
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 */; };
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 */; };
......@@ -171,13 +173,15 @@
96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; };
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarViewController.swift; sourceTree = "<group>"; };
96CC088A1C7FEC170034FF84 /* BasicCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewCell.swift; sourceTree = "<group>"; };
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionView.swift; sourceTree = "<group>"; };
96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewCell.swift; sourceTree = "<group>"; };
96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewDataSource.swift; sourceTree = "<group>"; };
96CC088E1C7FEC170034FF84 /* MaterialCollectionViewDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewDelegate.swift; sourceTree = "<group>"; };
96CC088F1C7FEC170034FF84 /* MaterialCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionViewLayout.swift; sourceTree = "<group>"; };
96CC08901C7FEC170034FF84 /* MaterialDataSourceItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialDataSourceItem.swift; sourceTree = "<group>"; };
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>"; };
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>"; };
......@@ -346,13 +350,15 @@
96CC08891C7FEBE10034FF84 /* CollectionView */ = {
isa = PBXGroup;
children = (
96CC088A1C7FEC170034FF84 /* BasicCollectionViewCell.swift */,
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */,
96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */,
96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */,
96CC088E1C7FEC170034FF84 /* MaterialCollectionViewDelegate.swift */,
96CC088F1C7FEC170034FF84 /* MaterialCollectionViewLayout.swift */,
96CC08901C7FEC170034FF84 /* MaterialDataSourceItem.swift */,
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */,
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */,
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */,
);
name = CollectionView;
sourceTree = "<group>";
......@@ -703,6 +709,7 @@
buildActionMask = 2147483647;
files = (
96D88C3D1C1328D800B91418 /* MaterialView.swift in Sources */,
96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */,
960B23481C38480E00E96216 /* TextView.swift in Sources */,
96D88C291C1328D800B91418 /* MaterialBasicAnimation.swift in Sources */,
96D88C3A1C1328D800B91418 /* MaterialTextLayer.swift in Sources */,
......@@ -721,6 +728,7 @@
96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */,
96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */,
96D88C231C1328D800B91418 /* FlatButton.swift in Sources */,
96CC089B1C80B82E0034FF84 /* BasicCollectionView.swift in Sources */,
966F57B81C226D75009185B7 /* TextField.swift in Sources */,
96DBA7361C61198400844821 /* Material+UIImage+Color.swift in Sources */,
96CC08931C7FEC170034FF84 /* MaterialCollectionViewCell.swift in Sources */,
......@@ -733,6 +741,7 @@
96D88C221C1328D800B91418 /* FabButton.swift in Sources */,
96D88C3F1C1328D800B91418 /* RaisedButton.swift in Sources */,
65FDC2EB1C66858A00103AC2 /* Menu.swift in Sources */,
96CC08991C80B74F0034FF84 /* BasicCollectionViewCell.swift in Sources */,
960B23311C383EAA00E96216 /* Material+UIImage+PhotoLibrary.swift in Sources */,
960B23321C383EAA00E96216 /* Material+UIImage+Resize.swift in Sources */,
96D88C3C1C1328D800B91418 /* MaterialTransitionAnimation.swift in Sources */,
......@@ -757,7 +766,6 @@
96D88C341C1328D800B91418 /* MaterialLayer.swift in Sources */,
96D88C461C1328D800B91418 /* SideNavigationViewController.swift in Sources */,
96D88C381C1328D800B91418 /* MaterialShape.swift in Sources */,
96CC08911C7FEC170034FF84 /* BasicCollectionViewCell.swift in Sources */,
960B23331C383EAA00E96216 /* Material+UIImage+Size.swift in Sources */,
9626C2DE1C795017007CA8E0 /* MenuViewController.swift in Sources */,
96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */,
......
/*
* 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 class BasicCollectionView : MaterialCollectionView {
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
An initializer that initializes the object.
- Parameter frame: A CGRect defining the view's frame.
*/
public override init(frame: CGRect) {
super.init(frame: frame, collectionViewLayout: BasicCollectionViewLayout())
prepareView()
}
/// A convenience initializer that initializes the object.
public convenience init() {
self.init(frame: CGRectNull)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero
}
}
......@@ -30,6 +30,12 @@
import UIKit
public enum BasicCollectionViewCellSize {
case Small
case Default
case Large
}
public class BasicCollectionViewCell : MaterialCollectionViewCell {
/// An Optional title UILabel.
public var titleLabel: UILabel? {
......@@ -39,7 +45,7 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
}
/// An Optional detail UILabel.
public var detailView: UIView? {
public var detailLabel: UILabel? {
didSet {
reloadView()
}
......@@ -68,8 +74,6 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
/// Reloads the view.
public func reloadView() {
contentView.grid.views = []
contentView.grid.axis.rows = 12
contentView.grid.axis.inherited = false
contentView.grid.axis.direction = .Vertical
for v in contentView.subviews {
......@@ -80,22 +84,22 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
var b: Int = 0
var c: Int = 0
if nil != titleLabel && nil == detailView && nil == controlView {
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = 12
} else if nil == titleLabel && nil != detailView && nil == controlView {
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = 12
} else if nil == titleLabel && nil == detailView && nil != controlView {
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = 12
} else if nil != titleLabel && nil != detailView && nil == controlView {
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 3
b = 9
} else if nil != titleLabel && nil == detailView && nil != controlView {
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = 9
c = 3
} else if nil == titleLabel && nil != detailView && nil != controlView {
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = 9
c = 3
} else if nil != titleLabel && nil != detailView && nil != controlView {
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 3
b = 6
c = 3
......@@ -107,7 +111,7 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
contentView.grid.views?.append(v)
}
if let v: UIView = detailView {
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
......@@ -119,6 +123,10 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
}
}
/*
* 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 class BasicCollectionViewLayout : MaterialCollectionViewLayout {
}
......@@ -58,6 +58,11 @@ public class MaterialCollectionView : UICollectionView {
prepareView()
}
/// A convenience initializer that initializes the object.
public convenience init() {
self.init(frame: CGRectNull)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
......
......@@ -33,5 +33,5 @@ public protocol MaterialCollectionViewDataSource : MaterialDelegate, UICollectio
Retrieves the items for the collectionView.
- Returns: An Array of Arrays of MaterialDataSourceItem objects.
*/
func items() -> Array<Array<MaterialDataSourceItem>>
func items() -> Array<MaterialDataSourceItem>
}
\ No newline at end of file
......@@ -31,6 +31,9 @@
import UIKit
public class MaterialCollectionViewLayout : UICollectionViewLayout {
/// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPointZero
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
......@@ -42,23 +45,17 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public var contentInset: UIEdgeInsets = UIEdgeInsetsZero
/// Size of the content.
private var contentSize: CGSize = CGSizeZero
public private(set) var contentSize: CGSize = CGSizeZero
/// Layout attribute items.
private var layoutItems: Array<(UICollectionViewLayoutAttributes, NSIndexPath)> = Array<(UICollectionViewLayoutAttributes, NSIndexPath)>()
/// Used to calculate the dimensions of the cells.
private var offset: CGPoint = CGPointZero
public private(set) var layoutItems: Array<(UICollectionViewLayoutAttributes, NSIndexPath)> = Array<(UICollectionViewLayoutAttributes, NSIndexPath)>()
/// Cell items.
private var items: Array<Array<MaterialDataSourceItem>>?
public private(set) var items: Array<MaterialDataSourceItem>?
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection = .Vertical
/// Scale of the screen.
public var scale: CGFloat = 2
/// Spacing between items.
public var spacing: CGFloat = 0
......@@ -79,7 +76,7 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
let item: MaterialDataSourceItem = items![indexPath.section][indexPath.item]
let item: MaterialDataSourceItem = items![indexPath.item]
switch scrollDirection {
case .Vertical:
......@@ -121,10 +118,8 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
var indexPath: NSIndexPath?
for var i: Int = 0, l: Int = items!.count - 1; i <= l; ++i {
let v: Array<MaterialDataSourceItem> = items![i]
for var j: Int = 0, k: Int = v.count - 1; j <= k; ++j {
let item: MaterialDataSourceItem = v[j]
indexPath = NSIndexPath(forItem: j, inSection: i)
let item: MaterialDataSourceItem = items![i]
indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
offset.x += spacing
......@@ -133,7 +128,6 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
offset.y += spacing
offset.y += nil == item.height ? 0 : item.height!
}
}
offset.x += contentInset.right - spacing
offset.y += contentInset.bottom - spacing
......
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