Commit eefc513b by Daniel Dahan

working version of BasicCollectionViewCell

parent b2e465a7
......@@ -71,7 +71,7 @@ class AppLeftViewController: UIViewController {
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.blueGrey.darken4
view.backgroundColor = MaterialColor.grey.darken4
}
/// Prepares the items that are displayed within the tableView.
......@@ -164,7 +164,7 @@ extension AppLeftViewController: UITableViewDelegate {
let item: Item = items[indexPath.row]
if let a: MenuViewController = sideNavigationViewController?.mainViewController as? MenuViewController {
if let b: NavigationBarViewController = a.mainViewController as? NavigationBarViewController {
b.transitionFromMainViewController("Feed" == item.text ? FeedViewController() : InboxViewController(), duration: 0.75, options: [.TransitionCrossDissolve]) { [weak self] _ in
b.transitionFromMainViewController("Feed" == item.text ? FeedViewController() : InboxViewController(), options: [.TransitionCrossDissolve]) { [weak self] _ in
self?.sideNavigationViewController?.closeLeftView()
}
}
......
......@@ -58,7 +58,7 @@ class AppRightViewController: UIViewController {
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.blueGrey.darken4
view.backgroundColor = MaterialColor.grey.darken4
}
override func viewWillAppear(animated: Bool) {
......
......@@ -79,18 +79,18 @@ class AppSearchBarViewController: SearchBarViewController {
var image = UIImage(named: "ic_close_white")?.imageWithRenderingMode(.AlwaysTemplate)
let clearButton: FlatButton = FlatButton()
clearButton.pulseColor = MaterialColor.blueGrey.darken4
clearButton.pulseColor = MaterialColor.grey.darken4
clearButton.pulseScale = false
clearButton.tintColor = MaterialColor.blueGrey.darken4
clearButton.tintColor = MaterialColor.grey.darken4
clearButton.setImage(image, forState: .Normal)
clearButton.setImage(image, forState: .Highlighted)
// Back button.
image = UIImage(named: "ic_arrow_back_white")?.imageWithRenderingMode(.AlwaysTemplate)
let backButton: FlatButton = FlatButton()
backButton.pulseColor = MaterialColor.blueGrey.darken4
backButton.pulseColor = MaterialColor.grey.darken4
backButton.pulseScale = false
backButton.tintColor = MaterialColor.blueGrey.darken4
backButton.tintColor = MaterialColor.grey.darken4
backButton.setImage(image, forState: .Normal)
backButton.setImage(image, forState: .Highlighted)
backButton.addTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
......@@ -98,18 +98,18 @@ class AppSearchBarViewController: SearchBarViewController {
// More button.
image = UIImage(named: "ic_more_horiz_white")?.imageWithRenderingMode(.AlwaysTemplate)
let moreButton: FlatButton = FlatButton()
moreButton.pulseColor = MaterialColor.blueGrey.darken4
moreButton.pulseColor = MaterialColor.grey.darken4
moreButton.pulseScale = false
moreButton.tintColor = MaterialColor.blueGrey.darken4
moreButton.tintColor = MaterialColor.grey.darken4
moreButton.setImage(image, forState: .Normal)
moreButton.setImage(image, forState: .Highlighted)
moreButton.addTarget(self, action: "handleMoreButton", forControlEvents: .TouchUpInside)
searchBarView.delegate = self
searchBarView.placeholder = "Search"
searchBarView.tintColor = MaterialColor.blueGrey.darken4
searchBarView.textColor = MaterialColor.blueGrey.darken4
searchBarView.placeholderTextColor = MaterialColor.blueGrey.darken4
searchBarView.tintColor = MaterialColor.grey.darken4
searchBarView.textColor = MaterialColor.grey.darken4
searchBarView.placeholderTextColor = MaterialColor.grey.darken4
searchBarView.textField.font = RobotoFont.regularWithSize(17)
searchBarView.textField.delegate = self
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_share_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_share_white_18pt.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_18pt_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_share_white_18pt_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -72,18 +72,12 @@ 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...", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Large),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Small),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Large),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "#Pumpkin #pie - Preheat oven to 425 degrees F. Whisk pumpkin, sweetened condensed milk, eggs...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Wow!!! I really really need this fabulous pair. Action is ending tonight #sneakerhead", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Discovered an amazing #cofeeshop with the best #latte at Adelaide and Spadina #Toronto They also...", "date": "February 26, 2016"], dataSourceItemSize: .Default),
MaterialDataSourceItem(data: ["title": "Material", "detail": "Talk to that agency guy, a friend of #Jen, about renting...", "date": "February 26, 2016"], dataSourceItemSize: .Default)
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)
]
}
......@@ -102,40 +96,42 @@ extension FeedViewController: MaterialCollectionViewDataSource {
let c: BasicCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! BasicCollectionViewCell
let item: MaterialDataSourceItem = items()[indexPath.item]
c.backgroundColor = MaterialColor.blue.base
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
titleLabel.textColor = MaterialColor.grey.darken4
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]
// }
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.grey.darken4
c.detailLabel = detailLabel
}
if nil == c.controlView {
c.controlView = ControlView()
c.controlView!.backgroundColor = nil
let image = UIImage(named: "ic_share_white_18pt")?.imageWithRenderingMode(.AlwaysTemplate)
// Share button.
let shareButton: FlatButton = FlatButton()
shareButton.pulseScale = false
shareButton.pulseColor = MaterialColor.grey.lighten1
shareButton.tintColor = MaterialColor.grey.base
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
c.controlView?.rightControls = [shareButton]
}
c.titleLabel?.text = data["title"] as? String
c.detailLabel?.text = data["detail"] as? String
......
......@@ -290,7 +290,6 @@ class ViewController: UIViewController {
alarmButton.grid.offset.columns = 10
contentView.grid.spacing = 8
contentView.grid.axis.inherited = false
contentView.grid.axis.direction = .None
contentView.grid.contentInsetPreset = .Square3
contentView.grid.views = [
......@@ -388,7 +387,6 @@ class ViewController: UIViewController {
alarmButton.grid.offset.columns = 9
contentView.grid.spacing = 8
contentView.grid.axis.inherited = false
contentView.grid.axis.direction = .None
contentView.grid.contentInsetPreset = .Square3
contentView.grid.views = [
......@@ -513,7 +511,6 @@ class ViewController: UIViewController {
alarmButton.grid.offset.columns = 10
contentView.grid.spacing = 8
contentView.grid.axis.inherited = false
contentView.grid.axis.direction = .None
contentView.grid.contentInsetPreset = .Square3
contentView.grid.views = [
......
......@@ -352,7 +352,9 @@
96CC08891C7FEBE10034FF84 /* CollectionView */ = {
isa = PBXGroup;
children = (
96CC089E1C80BD550034FF84 /* Basic */,
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */,
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */,
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */,
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */,
96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */,
96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */,
......@@ -363,16 +365,6 @@
name = CollectionView;
sourceTree = "<group>";
};
96CC089E1C80BD550034FF84 /* Basic */ = {
isa = PBXGroup;
children = (
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */,
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */,
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */,
);
name = Basic;
sourceTree = "<group>";
};
96D88BF41C1328D800B91418 /* Sources */ = {
isa = PBXGroup;
children = (
......
......@@ -67,161 +67,94 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
*/
public override func prepareView() {
super.prepareView()
spacingPreset = .Spacing2
contentInsetPreset = .Square3
backgroundColor = MaterialColor.white
}
/// Reloads the view.
public func reloadView() {
contentView.grid.views = []
switch height {
case 192:
let rows: Int = Int(height / 48)
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
}
grid.views = []
contentView.grid.views = []
contentView.grid.axis.rows = 12
contentView.grid.axis.direction = .Vertical
controlView?.grid.axis.columns = 0 < width ? Int(width / 48) : 12
var a: Int = 0
var b: Int = 0
var c: Int = 0
switch height {
case 142:
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
a = 12
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
b = 12
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
c = 12
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
a = 4
b = 8
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
a = 8
c = 4
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
b = 8
c = 4
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
a = 4
b = 4
c = 4
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
case 144:
let rows: Int = Int(height / 48)
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
}
var a: Int = 0
var b: Int = 0
var c: Int = 0
case 192:
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
a = 12
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
b = 12
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
c = 12
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
a = 3
b = 9
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
a = 9
c = 3
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
b = 9
c = 3
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
}
if let v: UILabel = titleLabel {
v.grid.rows = a
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
v.grid.rows = b
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
if let v: ControlView = controlView {
v.grid.rows = c
contentView.addSubview(v)
contentView.grid.views?.append(v)
}
grid.views = [
contentView
]
contentView.grid.reloadLayout()
case 192:
let rows: Int = Int(height / 48)
contentView.grid.axis.direction = .Vertical
contentView.grid.axis.rows = rows
for v in contentView.subviews {
v.removeFromSuperview()
a = 3
b = 6
c = 3
}
var a: Int = 0
var b: Int = 0
var c: Int = 0
case 256:
if nil != titleLabel && nil == detailLabel && nil == controlView {
a = rows
a = 12
} else if nil == titleLabel && nil != detailLabel && nil == controlView {
b = rows
b = 12
} else if nil == titleLabel && nil == detailLabel && nil != controlView {
c = rows
c = 12
} else if nil != titleLabel && nil != detailLabel && nil == controlView {
a = 1
b = rows - 1
a = 2
b = 10
} else if nil != titleLabel && nil == detailLabel && nil != controlView {
a = rows - 1
c = 1
a = 10
c = 2
} else if nil == titleLabel && nil != detailLabel && nil != controlView {
b = rows - 1
c = 1
b = 10
c = 2
} else if nil != titleLabel && nil != detailLabel && nil != controlView {
a = 1
b = rows - 6
c = 1
a = 2
b = 8
c = 2
}
default:
return
}
if let v: UILabel = titleLabel {
......@@ -245,10 +178,8 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
grid.views = [
contentView
]
contentView.grid.reloadLayout()
default:
grid.views = []
contentView.grid.views = []
}
controlView?.reloadView()
}
}
......@@ -40,11 +40,11 @@ public class BasicCollectionViewLayout : MaterialCollectionViewLayout {
if let q: MaterialDataSourceItemSize = v.dataSourceItemSize {
switch q {
case .Small:
v.height = 96
case .Large:
v.height = 142
case .Default:
v.height = 192
default:
v.height = 144
case .Large:
v.height = 256
}
}
items[i] = v
......
......@@ -125,7 +125,6 @@ public class ControlView : MaterialView {
/// Reloads the view.
public func reloadView() {
layoutIfNeeded()
// clear constraints so new ones do not conflict
removeConstraints(constraints)
......@@ -177,6 +176,7 @@ public class ControlView : MaterialView {
contentView.grid.columns -= contentView.grid.offset.columns
grid.reloadLayout()
contentView.grid.reloadLayout()
}
}
......
......@@ -41,7 +41,7 @@ public class GridAxis {
unowned var grid: Grid
/// Inherit grid rows and columns.
public var inherited: Bool = true
public var inherited: Bool = false
/// The direction the grid layouts its views out.
public var direction: GridAxisDirection = .Horizontal
......
......@@ -71,10 +71,6 @@ public class NavigationBarView : StatusBarView {
public override func layoutSubviews() {
super.layoutSubviews()
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
// TitleView alignment.
if let v: UILabel = titleLabel {
if let d: UILabel = detailLabel {
......@@ -119,7 +115,6 @@ public class NavigationBarView : StatusBarView {
*/
public override func prepareView() {
super.prepareView()
contentView.grid.axis.inherited = false
contentView.grid.axis.direction = .Vertical
}
......
......@@ -85,14 +85,6 @@ public class SearchBarView : StatusBarView {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
}
public override func layoutSubviews() {
super.layoutSubviews()
grid.axis.columns = Int(width / 48)
reloadView()
}
public override func didMoveToSuperview() {
super.didMoveToSuperview()
reloadView()
......@@ -103,9 +95,8 @@ public class SearchBarView : StatusBarView {
super.reloadView()
textField.grid.columns = contentView.grid.columns
textField.reloadView()
grid.reloadLayout()
textField.reloadView()
}
/**
......
......@@ -60,6 +60,7 @@ public class StatusBarView : ControlView {
super.layoutSubviews()
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
// General alignment.
if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
......@@ -101,7 +102,6 @@ public class StatusBarView : ControlView {
grid.contentInset.left = 8
grid.contentInset.bottom = 8
grid.contentInset.right = 8
grid.axis.inherited = false
}
/// 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