Commit 5e6d8784 by Daniel Dahan

NavigationBar working with all device sizes.

parent 92f6000c
...@@ -44,6 +44,9 @@ class InboxViewController: UIViewController { ...@@ -44,6 +44,9 @@ class InboxViewController: UIViewController {
/// NavigationBar detail label. /// NavigationBar detail label.
private var detailLabel: UILabel! private var detailLabel: UILabel!
/// NavigationBar share button.
private var shareButton: FlatButton!
/// A tableView used to display Bond entries. /// A tableView used to display Bond entries.
private var tableView: UITableView! private var tableView: UITableView!
...@@ -55,6 +58,7 @@ class InboxViewController: UIViewController { ...@@ -55,6 +58,7 @@ class InboxViewController: UIViewController {
prepareItems() prepareItems()
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
prepareShareButton()
prepareNavigationBar() prepareNavigationBar()
prepareTableView() prepareTableView()
} }
...@@ -84,6 +88,7 @@ class InboxViewController: UIViewController { ...@@ -84,6 +88,7 @@ class InboxViewController: UIViewController {
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel navigationItem.detailLabel = detailLabel
navigationItem.rightControls = [shareButton]
} }
/// Prepares the items Array. /// Prepares the items Array.
...@@ -127,6 +132,16 @@ class InboxViewController: UIViewController { ...@@ -127,6 +132,16 @@ class InboxViewController: UIViewController {
detailLabel.textAlignment = .Left detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white detailLabel.textColor = MaterialColor.white
} }
/// Prepares the shareButton.
private func prepareShareButton() {
let image: UIImage? = MaterialIcon.share
shareButton = FlatButton()
shareButton.pulseScale = false
shareButton.pulseColor = MaterialColor.white
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
}
} }
/// TableViewDataSource methods. /// TableViewDataSource methods.
......
...@@ -103,10 +103,14 @@ class ViewController: UIViewController { ...@@ -103,10 +103,14 @@ class ViewController: UIViewController {
/// Prepare navigationBar. /// Prepare navigationBar.
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationBar = NavigationBar() navigationBar = NavigationBar()
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base
view.addSubview(navigationBar) view.addSubview(navigationBar)
menuButton.backgroundColor = MaterialColor.yellow.accent1
let item: UINavigationItem = UINavigationItem() let item: UINavigationItem = UINavigationItem()
item.titleLabel = titleLabel item.titleLabel = titleLabel
item.leftControls = [menuButton] item.leftControls = [menuButton]
......
...@@ -249,7 +249,10 @@ public class NavigationBar : UINavigationBar { ...@@ -249,7 +249,10 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if let item: UINavigationItem = topItem {
if let item: UINavigationItem = backItem {
item.titleView?.grid.reloadLayout()
} else if let item: UINavigationItem = topItem {
layoutNavigationItem(item) layoutNavigationItem(item)
} }
} }
...@@ -267,6 +270,7 @@ public class NavigationBar : UINavigationBar { ...@@ -267,6 +270,7 @@ public class NavigationBar : UINavigationBar {
prepareItem(item) prepareItem(item)
let h: CGFloat = intrinsicContentSize().height let h: CGFloat = intrinsicContentSize().height
let w: CGFloat = backButton.intrinsicContentSize().width
let inset: CGFloat = MaterialDevice.landscape ? item.landscapeInset : item.portraitInset let inset: CGFloat = MaterialDevice.landscape ? item.landscapeInset : item.portraitInset
// leftControls // leftControls
...@@ -277,7 +281,7 @@ public class NavigationBar : UINavigationBar { ...@@ -277,7 +281,7 @@ public class NavigationBar : UINavigationBar {
b.contentEdgeInsets.top = 0 b.contentEdgeInsets.top = 0
b.contentEdgeInsets.bottom = 0 b.contentEdgeInsets.bottom = 0
} }
c.bounds.size = c is MaterialSwitch ? CGSizeMake(backButton.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom) c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
n.append(UIBarButtonItem(customView: c)) n.append(UIBarButtonItem(customView: c))
} }
...@@ -290,11 +294,12 @@ public class NavigationBar : UINavigationBar { ...@@ -290,11 +294,12 @@ public class NavigationBar : UINavigationBar {
} }
if nil == item.titleView { if nil == item.titleView {
item.titleView = UIView(frame: CGRectMake(0, contentInset.top, MaterialDevice.width < MaterialDevice.height ? MaterialDevice.height : MaterialDevice.width, h - contentInset.top - contentInset.bottom)) item.titleView = UIView()
item.titleView!.backgroundColor = nil item.titleView!.backgroundColor = nil
item.titleView!.grid.axis.direction = .Vertical item.titleView!.grid.axis.direction = .Vertical
} }
item.titleView!.frame = CGRectMake(0, contentInset.top, MaterialDevice.width < MaterialDevice.height ? MaterialDevice.height : MaterialDevice.width, h - contentInset.top - contentInset.bottom)
item.titleView!.grid.views = [] item.titleView!.grid.views = []
// TitleView alignment. // TitleView alignment.
...@@ -334,13 +339,13 @@ public class NavigationBar : UINavigationBar { ...@@ -334,13 +339,13 @@ public class NavigationBar : UINavigationBar {
b.contentEdgeInsets.top = 0 b.contentEdgeInsets.top = 0
b.contentEdgeInsets.bottom = 0 b.contentEdgeInsets.bottom = 0
} }
c.bounds.size = c is MaterialSwitch ? CGSizeMake(backButton.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom) c.bounds.size = c is MaterialSwitch ? CGSizeMake(w, h - contentInset.top - contentInset.bottom) : CGSizeMake(c.intrinsicContentSize().width, h - contentInset.top - contentInset.bottom)
n.append(UIBarButtonItem(customView: c)) n.append(UIBarButtonItem(customView: c))
} }
// The spacer moves the UIBarButtonItems to the edge of the UINavigationBar. // The spacer moves the UIBarButtonItems to the edge of the UINavigationBar.
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil) let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = inset + contentInset.left spacer.width = inset + contentInset.right
n.append(spacer) n.append(spacer)
item.rightBarButtonItems = n.reverse() item.rightBarButtonItems = n.reverse()
...@@ -362,6 +367,7 @@ public class NavigationBar : UINavigationBar { ...@@ -362,6 +367,7 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
contentInset = UIEdgeInsetsMake(2, 6, 2, 6)
prepareBackButton() prepareBackButton()
} }
...@@ -375,9 +381,7 @@ public class NavigationBar : UINavigationBar { ...@@ -375,9 +381,7 @@ 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 { item.title = ""
item.title = ""
}
} }
} }
......
...@@ -64,16 +64,6 @@ public class NavigationController : UINavigationController { ...@@ -64,16 +64,6 @@ public class NavigationController : UINavigationController {
interactivePopGestureRecognizer?.delegate = nil interactivePopGestureRecognizer?.delegate = nil
} }
public override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if let v: UINavigationItem = navigationBar.topItem {
if let b: NavigationBar = navigationBar as? NavigationBar {
b.layoutNavigationItem(v)
}
}
}
/** /**
Delegation method that is called when a new UINavigationItem is about to be pushed. Delegation method that is called when a new UINavigationItem is about to be pushed.
This is used to prepare the transitions between UIViewControllers on the stack. This is used to prepare the transitions between UIViewControllers on the stack.
......
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