Commit 602f184d by Daniel Dahan

updated grid to include a layout inset

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