Commit 165620da by Daniel Dahan

updated NavigationBar internals

parent 2db722d6
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
......
...@@ -165,7 +165,7 @@ class RecipesViewController: UIViewController { ...@@ -165,7 +165,7 @@ class RecipesViewController: UIViewController {
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.text = "Recipes" titleLabel.text = "Recipes"
titleLabel.textAlignment = .Center titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
} }
...@@ -198,10 +198,9 @@ class RecipesViewController: UIViewController { ...@@ -198,10 +198,9 @@ class RecipesViewController: UIViewController {
/// Prepares the NavigationBar. /// Prepares the NavigationBar.
private func prepareNavigationBar() { private func prepareNavigationBar() {
// navigationItem.title = "Recipes"
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
// navigationItem.leftControls = [menuButton] navigationItem.leftControls = [menuButton]
// navigationItem.rightControls = [switchControl, searchButton] navigationItem.rightControls = [switchControl, searchButton]
} }
/// Prepares the tableView. /// Prepares the tableView.
......
...@@ -35,6 +35,9 @@ class ViewController: UIViewController { ...@@ -35,6 +35,9 @@ class ViewController: UIViewController {
/// NavigationBar title label. /// NavigationBar title label.
private var titleLabel: UILabel! private var titleLabel: UILabel!
/// NavigationBar detail label.
private var detailLabel: UILabel!
/// NavigationBar menu button. /// NavigationBar menu button.
private var menuButton: FlatButton! private var menuButton: FlatButton!
...@@ -51,6 +54,7 @@ class ViewController: UIViewController { ...@@ -51,6 +54,7 @@ class ViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel()
prepareMenuButton() prepareMenuButton()
prepareSwitchControl() prepareSwitchControl()
prepareSearchButton() prepareSearchButton()
...@@ -75,6 +79,14 @@ class ViewController: UIViewController { ...@@ -75,6 +79,14 @@ class ViewController: UIViewController {
titleLabel.textColor = MaterialColor.white titleLabel.textColor = MaterialColor.white
} }
/// Prepares the titleLabel.
private func prepareDetailLabel() {
detailLabel = UILabel()
detailLabel.text = "8 Items"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
}
/// Prepares the menuButton. /// Prepares the menuButton.
private func prepareMenuButton() { private func prepareMenuButton() {
let image: UIImage? = MaterialIcon.menu let image: UIImage? = MaterialIcon.menu
...@@ -111,6 +123,7 @@ class ViewController: UIViewController { ...@@ -111,6 +123,7 @@ class ViewController: UIViewController {
let item: UINavigationItem = UINavigationItem() let item: UINavigationItem = UINavigationItem()
item.titleLabel = titleLabel item.titleLabel = titleLabel
item.detailLabel = detailLabel
item.leftControls = [menuButton] item.leftControls = [menuButton]
item.rightControls = [switchControl, searchButton] item.rightControls = [switchControl, searchButton]
navigationBar.pushNavigationItem(item, animated: true) navigationBar.pushNavigationItem(item, animated: true)
......
...@@ -254,7 +254,44 @@ public class NavigationBar : UINavigationBar { ...@@ -254,7 +254,44 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
topItem?.titleView?.backgroundColor = MaterialColor.green.base
let h: CGFloat = intrinsicContentSize().height
let w: CGFloat = backButton.intrinsicContentSize().width
if let v: Array<UIControl> = topItem?.leftControls {
for c in v {
c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
}
}
if let t: UILabel = topItem?.titleLabel {
t.grid.rows = 1
topItem?.titleView?.grid.views = [t]
if 32 >= height || nil == topItem?.detailLabel {
t.font = t.font.fontWithSize(20)
topItem?.titleView?.grid.axis.rows = 1
topItem?.detailLabel?.hidden = true
} else if let d: UILabel = topItem?.detailLabel {
d.grid.rows = 1
d.hidden = false
d.font = d.font.fontWithSize(12)
t.font = t.font.fontWithSize(17)
topItem?.titleView?.grid.axis.rows = 2
topItem?.titleView?.grid.views?.append(d)
}
}
if let v: Array<UIControl> = topItem?.rightControls {
for c in v {
c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
}
}
topItem?.titleView?.grid.reloadLayout()
} }
public override func pushNavigationItem(item: UINavigationItem, animated: Bool) { public override func pushNavigationItem(item: UINavigationItem, animated: Bool) {
...@@ -293,10 +330,11 @@ public class NavigationBar : UINavigationBar { ...@@ -293,10 +330,11 @@ public class NavigationBar : UINavigationBar {
item.leftBarButtonItems = n.reverse() item.leftBarButtonItems = n.reverse()
} }
// If title is empty // Set the titleView if title is empty.
if "" == item.title { if nil == item.title {
if nil == item.titleView { if nil == item.titleView {
item.titleView = UIView(frame: CGRectMake(0, contentInset.top, MaterialDevice.width, h - contentInset.top - contentInset.bottom)) item.titleView = UIView(frame: CGRectMake(0, contentInset.top, MaterialDevice.width, h - contentInset.top - contentInset.bottom))
item.titleView!.autoresizingMask = .FlexibleWidth
item.titleView!.grid.axis.direction = .Vertical item.titleView!.grid.axis.direction = .Vertical
} }
...@@ -309,12 +347,7 @@ public class NavigationBar : UINavigationBar { ...@@ -309,12 +347,7 @@ public class NavigationBar : UINavigationBar {
item.titleView!.addSubview(t) item.titleView!.addSubview(t)
item.titleView!.grid.views?.append(t) item.titleView!.grid.views?.append(t)
if 32 >= height || nil == item.detailLabel { if let d: UILabel = item.detailLabel {
t.font = t.font?.fontWithSize(17)
item.titleView!.grid.axis.rows = 1
item.detailLabel?.hidden = true
} else if let d: UILabel = item.detailLabel {
d.grid.rows = 1 d.grid.rows = 1
d.hidden = false d.hidden = false
d.font = d.font.fontWithSize(12) d.font = d.font.fontWithSize(12)
...@@ -324,6 +357,11 @@ public class NavigationBar : UINavigationBar { ...@@ -324,6 +357,11 @@ public class NavigationBar : UINavigationBar {
item.titleView!.addSubview(d) item.titleView!.addSubview(d)
item.titleView!.grid.axis.rows = 2 item.titleView!.grid.axis.rows = 2
item.titleView!.grid.views?.append(d) item.titleView!.grid.views?.append(d)
} else {
t.font = t.font?.fontWithSize(20)
item.titleView!.grid.axis.rows = 1
item.detailLabel?.hidden = true
} }
} else if let d: UIView = item.detailView { } else if let d: UIView = item.detailView {
d.grid.rows = 1 d.grid.rows = 1
...@@ -382,8 +420,8 @@ public class NavigationBar : UINavigationBar { ...@@ -382,8 +420,8 @@ public class NavigationBar : UINavigationBar {
/// Prepares the UINavigationItem for layout and sizing. /// Prepares the UINavigationItem for layout and sizing.
internal func prepareItem(item: UINavigationItem) { internal func prepareItem(item: UINavigationItem) {
if nil == item.title { if "" == item.title {
item.title = "" item.title = nil
} }
} }
} }
......
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