Commit ea72a610 by Daniel Dahan

added centerViews to Bar and updated Card samples

parent 54a2e6d0
...@@ -46,7 +46,7 @@ class ViewController: UIViewController { ...@@ -46,7 +46,7 @@ class ViewController: UIViewController {
/// Toolbar views. /// Toolbar views.
private var toolbar: Toolbar! private var toolbar: Toolbar!
private var moreButton: IconButton! private var moreButton: IconButton!
private var authorView: View! private var authorView: UIImageView!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -77,7 +77,6 @@ class ViewController: UIViewController { ...@@ -77,7 +77,6 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() { private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.red.base) favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.red.base)
favoriteButton.grid.columns = 4
} }
private func prepareMoreButton() { private func prepareMoreButton() {
...@@ -85,16 +84,13 @@ class ViewController: UIViewController { ...@@ -85,16 +84,13 @@ class ViewController: UIViewController {
} }
private func prepareAuthorView() { private func prepareAuthorView() {
authorView = View() authorView = UIImageView()
authorView.width = 24 authorView.image = UIImage(named: "CosmicMind")?.resize(toWidth: 24)
authorView.image = UIImage(named: "CosmicMind") authorView.contentMode = .scaleAspectFit
authorView.backgroundColor = nil
authorView.contentsGravityPreset = .ResizeAspect
} }
private func prepareToolbar() { private func prepareToolbar() {
toolbar = Toolbar() toolbar = Toolbar(leftViews: [authorView], rightViews: [moreButton])
toolbar.backgroundColor = nil
toolbar.title = "CosmicMind" toolbar.title = "CosmicMind"
toolbar.titleLabel.textAlignment = .left toolbar.titleLabel.textAlignment = .left
...@@ -102,21 +98,17 @@ class ViewController: UIViewController { ...@@ -102,21 +98,17 @@ class ViewController: UIViewController {
toolbar.detail = "Build Beautiful Software" toolbar.detail = "Build Beautiful Software"
toolbar.detailLabel.textAlignment = .left toolbar.detailLabel.textAlignment = .left
toolbar.detailLabel.textColor = Color.blueGrey.base toolbar.detailLabel.textColor = Color.blueGrey.base
toolbar.leftViews = [authorView]
toolbar.rightViews = [moreButton]
} }
private func prepareContentView() { private func prepareContentView() {
contentView = UILabel() contentView = UILabel()
contentView.numberOfLines = 0 contentView.numberOfLines = 0
contentView.text = "Material is an animation and graphics framework that is the foundation for creating beautiful applications." contentView.text = "Material is an animation and graphics framework that is used for creating beautiful applications."
contentView.font = RobotoFont.regular(with: 14) contentView.font = RobotoFont.regular(with: 14)
} }
private func prepareBottomBar() { private func prepareBottomBar() {
bottomBar = Bar() bottomBar = Bar()
bottomBar.cornerRadiusPreset = .cornerRadius1
bottomBar.leftViews = [dateLabel] bottomBar.leftViews = [dateLabel]
bottomBar.rightViews = [favoriteButton] bottomBar.rightViews = [favoriteButton]
...@@ -124,16 +116,15 @@ class ViewController: UIViewController { ...@@ -124,16 +116,15 @@ class ViewController: UIViewController {
private func prepareImageCard() { private func prepareImageCard() {
card = Card() card = Card()
card.cornerRadiusPreset = .cornerRadius1
card.toolbar = toolbar card.toolbar = toolbar
card.toolbarEdgeInsetsPreset = .square1 card.toolbarEdgeInsetsPreset = .wideRectangle2
card.contentView = contentView card.contentView = contentView
card.contentViewEdgeInsetsPreset = .square3 card.contentViewEdgeInsetsPreset = .wideRectangle3
card.bottomBar = bottomBar card.bottomBar = bottomBar
card.bottomBarEdgeInsetsPreset = .square2 card.bottomBarEdgeInsetsPreset = .wideRectangle2
view.layout(card).horizontally(left: 20, right: 20).center() view.layout(card).horizontally(left: 20, right: 20).center()
} }
......
...@@ -66,24 +66,19 @@ class ViewController: UIViewController { ...@@ -66,24 +66,19 @@ class ViewController: UIViewController {
private func prepareImageView() { private func prepareImageView() {
imageView = UIImageView() imageView = UIImageView()
imageView.image = UIImage(named: "frontier.jpg")?.resize(toWidth: view.width) imageView.image = UIImage(named: "frontier.jpg")?.resize(toWidth: view.width)
imageView.clipsToBounds = true
imageView.cornerRadiusPreset = .cornerRadius1
imageView.contentMode = .scaleAspectFill imageView.contentMode = .scaleAspectFill
} }
private func prepareFavoriteButton() { private func prepareFavoriteButton() {
favoriteButton = FlatButton(image: Icon.favorite, tintColor: Color.blueGrey.base) favoriteButton = FlatButton(image: Icon.favorite, tintColor: Color.blueGrey.base)
favoriteButton.grid.columns = 4
} }
private func prepareShareButton() { private func prepareShareButton() {
shareButton = FlatButton(image: Icon.cm.share, tintColor: Color.blueGrey.base) shareButton = FlatButton(image: Icon.cm.share, tintColor: Color.blueGrey.base)
shareButton.grid.columns = 4
} }
private func prepareStarButton() { private func prepareStarButton() {
starButton = FlatButton(image: Icon.cm.star, tintColor: Color.blueGrey.base) starButton = FlatButton(image: Icon.cm.star, tintColor: Color.blueGrey.base)
starButton.grid.columns = 4
} }
private func prepareMoreButton() { private func prepareMoreButton() {
...@@ -104,19 +99,17 @@ class ViewController: UIViewController { ...@@ -104,19 +99,17 @@ class ViewController: UIViewController {
private func prepareContentView() { private func prepareContentView() {
contentView = UILabel() contentView = UILabel()
contentView.numberOfLines = 0 contentView.numberOfLines = 0
contentView.text = "Material is an animation and graphics framework that is the foundation for creating beautiful applications." contentView.text = "Material is an animation and graphics framework that is used for creating beautiful applications."
contentView.font = RobotoFont.regular(with: 14) contentView.font = RobotoFont.regular(with: 14)
} }
private func prepareBottomBar() { private func prepareBottomBar() {
bottomBar = Bar() bottomBar = Bar(centerViews: [favoriteButton, shareButton, starButton])
bottomBar.backgroundColor = nil
bottomBar.contentView.grid.views = [favoriteButton, shareButton, starButton]
} }
private func prepareImageCard() { private func prepareImageCard() {
card = ImageCard() card = ImageCard()
card.imageView = imageView card.imageView = imageView
card.toolbar = toolbar card.toolbar = toolbar
...@@ -126,7 +119,6 @@ class ViewController: UIViewController { ...@@ -126,7 +119,6 @@ class ViewController: UIViewController {
card.contentViewEdgeInsetsPreset = .square3 card.contentViewEdgeInsetsPreset = .square3
card.bottomBar = bottomBar card.bottomBar = bottomBar
card.cornerRadiusPreset = .cornerRadius1
view.layout(card).horizontally(left: 20, right: 20).center() view.layout(card).horizontally(left: 20, right: 20).center()
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "dreamer.jpg", "filename" : "pattern.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
......
...@@ -67,8 +67,7 @@ class ViewController: UIViewController { ...@@ -67,8 +67,7 @@ class ViewController: UIViewController {
private func preparePresenterView() { private func preparePresenterView() {
presenterView = UIImageView() presenterView = UIImageView()
presenterView.image = UIImage(named: "dreamer.jpg")?.resize(toWidth: view.width) presenterView.image = UIImage(named: "pattern")?.resize(toWidth: view.width)
presenterView.clipsToBounds = true
presenterView.contentMode = .scaleAspectFill presenterView.contentMode = .scaleAspectFill
} }
...@@ -87,12 +86,10 @@ class ViewController: UIViewController { ...@@ -87,12 +86,10 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() { private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.red.base) favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.red.base)
favoriteButton.grid.columns = 4
} }
private func prepareShareButton() { private func prepareShareButton() {
shareButton = IconButton(image: Icon.cm.share, tintColor: Color.blueGrey.base) shareButton = IconButton(image: Icon.cm.share, tintColor: Color.blueGrey.base)
shareButton.grid.columns = 4
} }
private func prepareMoreButton() { private func prepareMoreButton() {
...@@ -100,41 +97,32 @@ class ViewController: UIViewController { ...@@ -100,41 +97,32 @@ class ViewController: UIViewController {
} }
private func prepareToolbar() { private func prepareToolbar() {
toolbar = Toolbar() toolbar = Toolbar(rightViews: [moreButton])
toolbar.backgroundColor = nil
toolbar.title = "Material" toolbar.title = "CosmicMind"
toolbar.titleLabel.textAlignment = .left toolbar.titleLabel.textAlignment = .left
toolbar.detail = "Build Beautiful Software" toolbar.detail = "Build Beautiful Software"
toolbar.detailLabel.textAlignment = .left toolbar.detailLabel.textAlignment = .left
toolbar.detailLabel.textColor = Color.blueGrey.base toolbar.detailLabel.textColor = Color.blueGrey.base
toolbar.rightViews = [moreButton]
} }
private func prepareContentView() { private func prepareContentView() {
contentView = UILabel() contentView = UILabel()
contentView.numberOfLines = 0 contentView.numberOfLines = 0
contentView.text = "Material is an animation and graphics framework that is the foundation for creating beautiful applications." contentView.text = "Material is an animation and graphics framework that is used for creating beautiful applications."
contentView.font = RobotoFont.regular(with: 14) contentView.font = RobotoFont.regular(with: 14)
} }
private func prepareBottomBar() { private func prepareBottomBar() {
bottomBar = Bar() bottomBar = Bar(leftViews: [favoriteButton], rightViews: [shareButton], centerViews: [dateLabel])
bottomBar.backgroundColor = nil
bottomBar.leftViews = [favoriteButton]
bottomBar.rightViews = [shareButton]
bottomBar.contentView.grid.views = [dateLabel]
} }
private func prepareImageCard() { private func prepareImageCard() {
card = PresenterCard() card = PresenterCard()
card.cornerRadiusPreset = .cornerRadius1
card.toolbar = toolbar card.toolbar = toolbar
card.toolbarEdgeInsetsPreset = .square2 card.toolbarEdgeInsetsPreset = .wideRectangle2
card.presenterView = presenterView card.presenterView = presenterView
...@@ -142,7 +130,7 @@ class ViewController: UIViewController { ...@@ -142,7 +130,7 @@ class ViewController: UIViewController {
card.contentViewEdgeInsetsPreset = .square3 card.contentViewEdgeInsetsPreset = .square3
card.bottomBar = bottomBar card.bottomBar = bottomBar
card.bottomBarEdgeInsetsPreset = .square1 card.bottomBarEdgeInsetsPreset = .wideRectangle2
view.layout(card).horizontally(left: 20, right: 20).center() view.layout(card).horizontally(left: 20, right: 20).center()
} }
......
...@@ -597,8 +597,8 @@ ...@@ -597,8 +597,8 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB75D1CB40DC500C806FE /* Card.swift */, 96BCB75D1CB40DC500C806FE /* Card.swift */,
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */,
96BCB7621CB40DC500C806FE /* ImageCard.swift */, 96BCB7621CB40DC500C806FE /* ImageCard.swift */,
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */,
); );
name = Card; name = Card;
sourceTree = "<group>"; sourceTree = "<group>";
......
...@@ -124,6 +124,16 @@ open class Bar: View { ...@@ -124,6 +124,16 @@ open class Bar: View {
} }
} }
/// Center UIViews.
open var centerViews: [UIView] {
get {
return contentView.grid.views
}
set(value) {
contentView.grid.views = 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.
...@@ -152,11 +162,13 @@ open class Bar: View { ...@@ -152,11 +162,13 @@ open class Bar: View {
A convenience initializer with parameter settings. A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side. - Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side. - Parameter rightViews: An Array of UIViews that go on the right side.
- Parameter centerViews: An Array of UIViews that go in the center.
*/ */
public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) { public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil, centerViews: [UIView]? = nil) {
self.leftViews = leftViews ?? [] self.leftViews = leftViews ?? []
self.rightViews = rightViews ?? [] self.rightViews = rightViews ?? []
super.init(frame: .zero) super.init(frame: .zero)
self.centerViews = centerViews ?? []
frame.size = intrinsicContentSize frame.size = intrinsicContentSize
} }
......
...@@ -36,6 +36,44 @@ open class Card: PulseView { ...@@ -36,6 +36,44 @@ open class Card: PulseView {
return 0 < width && nil != superview return 0 < width && nil != superview
} }
/// A container view for subviews.
open private(set) lazy var container = UIView()
@IBInspectable
open override var cornerRadiusPreset: CornerRadiusPreset {
didSet {
container.cornerRadiusPreset = cornerRadiusPreset
}
}
@IBInspectable
open override var cornerRadius: CGFloat {
didSet {
container.cornerRadius = cornerRadius
}
}
open override var shapePreset: ShapePreset {
didSet {
container.shapePreset = shapePreset
}
}
@IBInspectable
open override var backgroundColor: UIColor? {
didSet {
container.backgroundColor = backgroundColor
}
}
/// A reference to the toolbar.
@IBInspectable
open var toolbar: Toolbar? {
didSet {
layoutSubviews()
}
}
/// A preset wrapper around toolbarEdgeInsets. /// A preset wrapper around toolbarEdgeInsets.
open var toolbarEdgeInsetsPreset = EdgeInsetsPreset.none { open var toolbarEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet { didSet {
...@@ -51,9 +89,9 @@ open class Card: PulseView { ...@@ -51,9 +89,9 @@ open class Card: PulseView {
} }
} }
/// A reference to the toolbar. /// A reference to the contentView.
@IBInspectable @IBInspectable
open var toolbar: Toolbar? { open var contentView: UIView? {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -74,9 +112,9 @@ open class Card: PulseView { ...@@ -74,9 +112,9 @@ open class Card: PulseView {
} }
} }
/// A reference to the contentView. /// A reference to the bottomBar.
@IBInspectable @IBInspectable
open var contentView: UIView? { open var bottomBar: Bar? {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -97,14 +135,6 @@ open class Card: PulseView { ...@@ -97,14 +135,6 @@ open class Card: PulseView {
} }
} }
/// A reference to the bottomBar.
@IBInspectable
open var bottomBar: Bar? {
didSet {
layoutSubviews()
}
}
/** /**
An initializer that accepts a NSCoder. An initializer that accepts a NSCoder.
- Parameter coder aDecoder: A NSCoder. - Parameter coder aDecoder: A NSCoder.
...@@ -139,26 +169,21 @@ open class Card: PulseView { ...@@ -139,26 +169,21 @@ open class Card: PulseView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard willLayout else {
return
}
reload() reload()
} }
/// Reloads the layout. /// Reloads the layout.
open func reload() { open func reload() {
guard willLayout else { // Clear constraints so new ones do not conflict.
return container.removeConstraints(constraints)
} for v in container.subviews {
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
v.removeFromSuperview() v.removeFromSuperview()
} }
layout()
}
/// Lays out view.
open func layout() {
var format = "V:|" var format = "V:|"
var views = [String: Any]() var views = [String: Any]()
var metrics = [String: Any]() var metrics = [String: Any]()
...@@ -169,7 +194,7 @@ open class Card: PulseView { ...@@ -169,7 +194,7 @@ open class Card: PulseView {
format += "-(toolbarTop)-[toolbar]-(toolbarBottom)" format += "-(toolbarTop)-[toolbar]-(toolbarBottom)"
views["toolbar"] = v views["toolbar"] = v
layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right).height(v.height) container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right).height(v.height)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -186,7 +211,7 @@ open class Card: PulseView { ...@@ -186,7 +211,7 @@ open class Card: PulseView {
} }
views["contentView"] = v views["contentView"] = v
layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right) container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -206,7 +231,7 @@ open class Card: PulseView { ...@@ -206,7 +231,7 @@ open class Card: PulseView {
} }
views["bottomBar"] = v views["bottomBar"] = v
layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height) container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -215,7 +240,7 @@ open class Card: PulseView { ...@@ -215,7 +240,7 @@ open class Card: PulseView {
return return
} }
addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views)) container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
} }
/** /**
...@@ -229,6 +254,8 @@ open class Card: PulseView { ...@@ -229,6 +254,8 @@ open class Card: PulseView {
super.prepare() super.prepare()
depthPreset = .depth1 depthPreset = .depth1
pulseAnimation = .none pulseAnimation = .none
cornerRadiusPreset = .cornerRadius1
prepareContainer()
} }
/** /**
...@@ -242,4 +269,10 @@ open class Card: PulseView { ...@@ -242,4 +269,10 @@ open class Card: PulseView {
self.contentView = contentView self.contentView = contentView
self.bottomBar = bottomBar self.bottomBar = bottomBar
} }
/// Prepares the container.
private func prepareContainer() {
container.clipsToBounds = true
layout(container).edges()
}
} }
...@@ -188,7 +188,7 @@ public class Grid { ...@@ -188,7 +188,7 @@ public class Grid {
- Parameter columns: The number of columns, horizontal axis the grid will use. - Parameter columns: The number of columns, horizontal axis the grid will use.
- Parameter interimSpace: The interim space between rows or columns. - Parameter interimSpace: The interim space between rows or columns.
*/ */
public init(context: UIView?, rows: Int = 12, columns: Int = 12, interimSpace: InterimSpace = 0) { public init(context: UIView?, rows: Int = 0, columns: Int = 0, interimSpace: InterimSpace = 0) {
self.context = context self.context = context
self.rows = rows self.rows = rows
self.columns = columns self.columns = columns
...@@ -216,6 +216,7 @@ public class Grid { ...@@ -216,6 +216,7 @@ public class Grid {
var n: Int = 0 var n: Int = 0
var i: Int = 0 var i: Int = 0
var count = views.count
for child in views { for child in views {
guard let canvas = context else { guard let canvas = context else {
...@@ -229,7 +230,7 @@ public class Grid { ...@@ -229,7 +230,7 @@ public class Grid {
switch axis.direction { switch axis.direction {
case .horizontal: case .horizontal:
let c = child.grid.columns let c = 0 == child.grid.columns ? axis.columns / views.count : child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
...@@ -241,7 +242,7 @@ public class Grid { ...@@ -241,7 +242,7 @@ public class Grid {
n += c + co - 1 n += c + co - 1
case .vertical: case .vertical:
let r = child.grid.rows let r = 0 == child.grid.rows ? axis.rows / views.count : child.grid.rows
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
...@@ -253,9 +254,9 @@ public class Grid { ...@@ -253,9 +254,9 @@ public class Grid {
n += r + ro - 1 n += r + ro - 1
case .any: case .any:
let r = child.grid.rows let r = 0 == child.grid.rows ? axis.rows / views.count : child.grid.rows
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let c = child.grid.columns let c = 0 == child.grid.columns ? axis.columns / views.count : child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
......
...@@ -67,12 +67,18 @@ open class ImageCard: Card { ...@@ -67,12 +67,18 @@ open class ImageCard: Card {
} }
} }
open override func layout() { open override func reload() {
guard let iv = imageView else { guard let iv = imageView else {
super.layout() super.reload()
return return
} }
// Clear constraints so new ones do not conflict.
container.removeConstraints(constraints)
for v in container.subviews {
v.removeFromSuperview()
}
var format = "V:|" var format = "V:|"
var views = [String: Any]() var views = [String: Any]()
var metrics = [String: Any]() var metrics = [String: Any]()
...@@ -82,7 +88,7 @@ open class ImageCard: Card { ...@@ -82,7 +88,7 @@ open class ImageCard: Card {
format += "-(imageViewTop)-[imageView]-(imageViewBottom)" format += "-(imageViewTop)-[imageView]-(imageViewBottom)"
views["imageView"] = iv views["imageView"] = iv
layout(iv).horizontally(left: imageViewEdgeInsets.left, right: imageViewEdgeInsets.right) container.layout(iv).horizontally(left: imageViewEdgeInsets.left, right: imageViewEdgeInsets.right)
iv.divider.reload() iv.divider.reload()
if let v = toolbar { if let v = toolbar {
...@@ -103,7 +109,7 @@ open class ImageCard: Card { ...@@ -103,7 +109,7 @@ open class ImageCard: Card {
format += "-[contentView]-(contentViewBottom)" format += "-[contentView]-(contentViewBottom)"
views["contentView"] = v views["contentView"] = v
layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right) container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -120,7 +126,7 @@ open class ImageCard: Card { ...@@ -120,7 +126,7 @@ open class ImageCard: Card {
} }
views["bottomBar"] = v views["bottomBar"] = v
layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height) container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -129,6 +135,6 @@ open class ImageCard: Card { ...@@ -129,6 +135,6 @@ open class ImageCard: Card {
return return
} }
addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views)) container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
} }
} }
...@@ -54,7 +54,13 @@ open class PresenterCard: Card { ...@@ -54,7 +54,13 @@ open class PresenterCard: Card {
} }
} }
open override func layout() { open override func reload() {
// Clear constraints so new ones do not conflict.
container.removeConstraints(constraints)
for v in container.subviews {
v.removeFromSuperview()
}
var format = "V:|" var format = "V:|"
var views = [String: Any]() var views = [String: Any]()
var metrics = [String: Any]() var metrics = [String: Any]()
...@@ -65,7 +71,7 @@ open class PresenterCard: Card { ...@@ -65,7 +71,7 @@ open class PresenterCard: Card {
format += "-(toolbarTop)-[toolbar]-(toolbarBottom)" format += "-(toolbarTop)-[toolbar]-(toolbarBottom)"
views["toolbar"] = v views["toolbar"] = v
layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right).height(v.height) container.layout(v).horizontally(left: toolbarEdgeInsets.left, right: toolbarEdgeInsets.right).height(v.height)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -82,7 +88,7 @@ open class PresenterCard: Card { ...@@ -82,7 +88,7 @@ open class PresenterCard: Card {
} }
views["presenterView"] = v views["presenterView"] = v
layout(v).horizontally(left: presenterViewEdgeInsets.left, right: presenterViewEdgeInsets.right) container.layout(v).horizontally(left: presenterViewEdgeInsets.left, right: presenterViewEdgeInsets.right)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -102,7 +108,7 @@ open class PresenterCard: Card { ...@@ -102,7 +108,7 @@ open class PresenterCard: Card {
} }
views["contentView"] = v views["contentView"] = v
layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right) container.layout(v).horizontally(left: contentViewEdgeInsets.left, right: contentViewEdgeInsets.right)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -125,7 +131,7 @@ open class PresenterCard: Card { ...@@ -125,7 +131,7 @@ open class PresenterCard: Card {
} }
views["bottomBar"] = v views["bottomBar"] = v
layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height) container.layout(v).horizontally(left: bottomBarEdgeInsets.left, right: bottomBarEdgeInsets.right).height(v.height)
v.grid.reload() v.grid.reload()
v.divider.reload() v.divider.reload()
} }
...@@ -134,8 +140,6 @@ open class PresenterCard: Card { ...@@ -134,8 +140,6 @@ open class PresenterCard: Card {
return return
} }
print(format) container.addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
addConstraints(Layout.constraint(format: "\(format)-|", options: [], metrics: metrics, views: views))
} }
} }
...@@ -122,9 +122,10 @@ open class SearchBar: Bar { ...@@ -122,9 +122,10 @@ open class SearchBar: Bar {
A convenience initializer with parameter settings. A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side. - Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side. - Parameter rightViews: An Array of UIViews that go on the right side.
- Parameter centerViews: An Array of UIViews that go in the center.
*/ */
public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) { public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil, centerViews: [UIView]? = nil) {
super.init(leftViews: leftViews, rightViews: rightViews) super.init(leftViews: leftViews, rightViews: rightViews, centerViews: centerViews)
} }
/** /**
......
...@@ -87,9 +87,10 @@ open class Toolbar: Bar { ...@@ -87,9 +87,10 @@ open class Toolbar: Bar {
A convenience initializer with parameter settings. A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side. - Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side. - Parameter rightViews: An Array of UIViews that go on the right side.
- Parameter centerViews: An Array of UIViews that go in the center.
*/ */
public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) { public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil, centerViews: [UIView]? = nil) {
super.init(leftViews: leftViews, rightViews: rightViews) super.init(leftViews: leftViews, rightViews: rightViews, centerViews: centerViews)
} }
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
......
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