Commit 602f184d by Daniel Dahan

updated grid to include a layout inset

parent d84c2cd1
......@@ -77,7 +77,7 @@ class ViewController: UIViewController {
view.backgroundColor = MaterialColor.grey.lighten3
}
/// Prepares the tableView.
/// Prepares the collectionView.
private func prepareCollectionView() {
collectionView = MaterialCollectionView(frame: view.bounds)
collectionView.registerClass(MaterialCollectionViewCell.self, forCellWithReuseIdentifier: "MaterialCollectionViewCell")
......@@ -85,7 +85,6 @@ class ViewController: UIViewController {
collectionView.contentInset.top = 100
collectionView.spacing = 16
// Use MaterialLayout to easily align the tableView.
view.addSubview(collectionView)
MaterialLayout.alignToParent(view, child: collectionView)
}
......
......@@ -32,6 +32,15 @@ import UIKit
@IBDesignable
public class BarController : UIViewController {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/**
A Boolean property used to enable and disable interactivity
......
......@@ -31,16 +31,6 @@
import UIKit
public class BarView : ControlView {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
......
......@@ -217,7 +217,7 @@ public class ControlView : MaterialView {
}
public override func intrinsicContentSize() -> CGSize {
return CGSizeMake(width, 36 + contentInset.top + contentInset.bottom)
return CGSizeMake(width, 44)
}
/**
......
......@@ -126,6 +126,20 @@ public class Grid {
public private(set) var axis: GridAxis!
/// Preset inset value for grid.
public var layoutInsetPreset: MaterialEdgeInset = .None {
didSet {
layoutInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// Insets value for grid.
public var layoutInset: UIEdgeInsets = MaterialEdgeInsetToValue(.None) {
didSet {
reloadLayout()
}
}
/// Preset inset value for grid.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
......@@ -186,28 +200,28 @@ public class Grid {
sv.layoutIfNeeded()
switch axis.direction {
case .Horizontal:
let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right + spacing) / CGFloat(gc)
let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + spacing) / CGFloat(gc)
let c: Int = view.grid.columns
let co: Int = view.grid.offset.columns
let vh: CGFloat = sv.bounds.height - contentInset.top - contentInset.bottom
let vh: CGFloat = sv.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom
let vl: CGFloat = CGFloat(i + n + co) * w + contentInset.left
let vw: CGFloat = w * CGFloat(c) - spacing
view.frame = CGRectMake(vl, contentInset.top, vw, vh)
n += c + co - 1
case .Vertical:
let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom + spacing) / CGFloat(gr)
let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + spacing) / CGFloat(gr)
let r: Int = view.grid.rows
let ro: Int = view.grid.offset.rows
let vw: CGFloat = sv.bounds.width - contentInset.left - contentInset.right
let vw: CGFloat = sv.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right
let vt: CGFloat = CGFloat(i + n + ro) * h + contentInset.top
let vh: CGFloat = h * CGFloat(r) - spacing
view.frame = CGRectMake(contentInset.left, vt, vw, vh)
n += r + ro - 1
case .None:
let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right + spacing) / CGFloat(gc)
let w: CGFloat = (sv.bounds.width - contentInset.left - contentInset.right - layoutInset.left - layoutInset.right + spacing) / CGFloat(gc)
let c: Int = view.grid.columns
let co: Int = view.grid.offset.columns
let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom + spacing) / CGFloat(gr)
let h: CGFloat = (sv.bounds.height - contentInset.top - contentInset.bottom - layoutInset.top - layoutInset.bottom + spacing) / CGFloat(gr)
let r: Int = view.grid.rows
let ro: Int = view.grid.offset.rows
let vt: CGFloat = CGFloat(ro) * h + contentInset.top
......
......@@ -159,15 +159,11 @@ public class ToolbarController : BarController {
/// Layout subviews.
public func layoutSubviews() {
if let v: Toolbar = toolbar {
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
v.contentInset.top = 4
} else {
v.contentInset.top = 24
}
v.grid.layoutInset.top = .iPhone == MaterialDevice.type && MaterialDevice.isLandscape ? 0 : 20
let h: CGFloat = MaterialDevice.height
let w: CGFloat = MaterialDevice.width
let p: CGFloat = v.intrinsicContentSize().height
let p: CGFloat = v.intrinsicContentSize().height + v.grid.layoutInset.top
v.width = w
v.height = p
......
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