Commit eac04161 by Daniel Dahan

updated App example project with BasicCollectionView and…

updated App example project with BasicCollectionView and SideNavigationViewController loading UIViewControllers example
parent eefc513b
......@@ -60,10 +60,8 @@ class FeedViewController: UIViewController {
private func prepareCollectionView() {
collectionView.dataSource = self
collectionView.delegate = self
collectionView.registerClass(BasicCollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.spacingPreset = .Spacing1
collectionView.contentInsetPreset = .Square1
view.addSubview(collectionView)
}
}
......@@ -72,12 +70,54 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves the items for the collectionView.
func items() -> Array<MaterialDataSourceItem> {
return [
MaterialDataSourceItem(data: ["title": "MaterialColor", "detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "MaterialLayer", "detail": "MaterialLayer is a lightweight CAShapeLayer used throughout Material. It is designed to easily take shape, depth, and animations.", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "MaterialView", "detail": "MaterialView is the base UIView class used throughout Material. Like MaterialLayer, it is designed to easily take shape, depth, and animations. The major difference is that MaterialView has all the added features of the UIView class.", "date": "February 26, 2016"], dataSourceItemSize: .Large),
MaterialDataSourceItem(data: ["title": "MaterialPulseView", "detail": "MaterialPulseView is at the heart of all pulse animations. Any view that subclasses MaterialPulseView instantly inherits the pulse animation with full customizability.", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "TextField", "detail": "A TextField is an excellent way to improve UX. TextFields offer details that describe the usage and input results of text. For example, when a user enters an incorrect email, it is possible to display an error message under the TextField.", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "TextView", "detail": "A TextView is an excellent way to improve UX. TextViews offer details that describe the usage of text. In addition, TextViews may easily match any regular expression pattern in a body of text. Below is an example of the default hashtag pattern matching.", "date": "February 26, 2016"], dataSourceItemSize: .Large)
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
),
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
),
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
),
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
),
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
),
MaterialDataSourceItem(
data: [
"title": "MaterialColor",
"detail": "MaterialColor is a complete Material Design color library. It uses base color values that expand to a range of lighter and darker shades, with the addition of accents.",
"date": "February 26, 2016"
],
itemSize: .Small
)
]
}
......@@ -93,10 +133,13 @@ extension FeedViewController: MaterialCollectionViewDataSource {
/// Retrieves a UICollectionViewCell.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("BasicCollectionViewCell", forIndexPath: indexPath) as! BasicCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.item]
// Set the data for the view objects.
if let data: Dictionary<String, AnyObject> = item.data as? Dictionary<String, AnyObject> {
// Only load the titleLabel if it has not been.
if nil == data["title"] {
c.titleLabel = nil
} else if nil == c.titleLabel {
......@@ -105,6 +148,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
c.titleLabel = titleLabel
}
// Only load the detailLabel if it has not been.
if nil == data["detail"] {
c.detailLabel = nil
} else if nil == c.detailLabel {
......@@ -116,10 +160,24 @@ extension FeedViewController: MaterialCollectionViewDataSource {
c.detailLabel = detailLabel
}
// Only load the controlView if it has not been.
if nil == c.controlView {
c.controlView = ControlView()
c.controlView!.backgroundColor = nil
let date: UILabel = UILabel()
date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.base
/**
ControlViews have a contentView. In this example, I am using Grid
to maintain its alignment. A ControlView's contentView is inbetween
the leftControls and rightControls.
*/
c.controlView?.contentView.addSubview(date)
c.controlView?.contentView.grid.views = [date]
let image = UIImage(named: "ic_share_white_18pt")?.imageWithRenderingMode(.AlwaysTemplate)
// Share button.
......@@ -136,6 +194,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
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()
}
......
......@@ -63,5 +63,6 @@ public class BasicCollectionView : MaterialCollectionView {
public override func prepareView() {
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero
registerClass(BasicCollectionViewCell.self, forCellWithReuseIdentifier: "BasicCollectionViewCell")
}
}
......@@ -37,7 +37,7 @@ public class BasicCollectionViewLayout : MaterialCollectionViewLayout {
for var i: Int = items.count - 1; 0 <= i; --i {
var v: MaterialDataSourceItem = items[i]
if let q: MaterialDataSourceItemSize = v.dataSourceItemSize {
if let q: MaterialDataSourceItemSize = v.itemSize {
switch q {
case .Small:
v.height = 142
......
......@@ -195,6 +195,7 @@ public class ControlView : MaterialView {
/// Prepares the contentView.
public func prepareContentView() {
contentView.backgroundColor = nil
contentView.grid.axis.direction = .Vertical
addSubview(contentView)
}
......
......@@ -42,14 +42,14 @@ public struct MaterialDataSourceItem {
public var y: CGFloat?
public var width: CGFloat?
public var height: CGFloat?
public var dataSourceItemSize: MaterialDataSourceItemSize?
public var itemSize: MaterialDataSourceItemSize?
public init(data: AnyObject? = nil, x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, dataSourceItemSize: MaterialDataSourceItemSize? = nil) {
public init(data: AnyObject? = nil, x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, itemSize: MaterialDataSourceItemSize? = nil) {
self.data = data
self.x = x
self.y = y
self.width = width
self.height = height
self.dataSourceItemSize = dataSourceItemSize
self.itemSize = itemSize
}
}
\ No newline at end of file
......@@ -106,18 +106,6 @@ public class NavigationBarView : StatusBarView {
contentView.grid.reloadLayout()
}
/**
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() {
super.prepareView()
contentView.grid.axis.direction = .Vertical
}
/// Called when the NavigationBarView changes size.
public override func statusBarViewDidChangeLayout() {
(delegate as? NavigationBarViewDelegate)?.navigationBarViewDidChangeLayout?(self)
......
......@@ -85,20 +85,6 @@ public class SearchBarView : StatusBarView {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
}
public override func didMoveToSuperview() {
super.didMoveToSuperview()
reloadView()
}
/// Reloads the view.
public override func reloadView() {
super.reloadView()
textField.grid.columns = contentView.grid.columns
grid.reloadLayout()
textField.reloadView()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
......
......@@ -71,6 +71,8 @@ public class StatusBarView : ControlView {
height = 64
}
reloadView()
if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height {
oldFrame = frame
if nil != delegate {
......@@ -98,10 +100,8 @@ public class StatusBarView : ControlView {
super.prepareView()
depth = .Depth1
oldFrame = frame
grid.spacing = 8
grid.contentInset.left = 8
grid.contentInset.bottom = 8
grid.contentInset.right = 8
grid.spacingPreset = .Spacing2
grid.contentInsetPreset = .Square2
}
/// Chaining method for subclasses to offer delegation or other useful features.
......
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