Commit 5e6d8784 by Daniel Dahan

NavigationBar working with all device sizes.

parent 92f6000c
......@@ -44,6 +44,9 @@ class InboxViewController: UIViewController {
/// NavigationBar detail label.
private var detailLabel: UILabel!
/// NavigationBar share button.
private var shareButton: FlatButton!
/// A tableView used to display Bond entries.
private var tableView: UITableView!
......@@ -55,6 +58,7 @@ class InboxViewController: UIViewController {
prepareItems()
prepareTitleLabel()
prepareDetailLabel()
prepareShareButton()
prepareNavigationBar()
prepareTableView()
}
......@@ -84,6 +88,7 @@ class InboxViewController: UIViewController {
private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
navigationItem.rightControls = [shareButton]
}
/// Prepares the items Array.
......@@ -127,6 +132,16 @@ class InboxViewController: UIViewController {
detailLabel.textAlignment = .Left
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.
......
......@@ -103,10 +103,14 @@ class ViewController: UIViewController {
/// Prepare navigationBar.
private func prepareNavigationBar() {
navigationBar = NavigationBar()
navigationBar.backgroundColor = MaterialColor.blue.base
navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base
view.addSubview(navigationBar)
menuButton.backgroundColor = MaterialColor.yellow.accent1
let item: UINavigationItem = UINavigationItem()
item.titleLabel = titleLabel
item.leftControls = [menuButton]
......
......@@ -249,7 +249,10 @@ public class NavigationBar : UINavigationBar {
public override func 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)
}
}
......@@ -267,6 +270,7 @@ public class NavigationBar : UINavigationBar {
prepareItem(item)
let h: CGFloat = intrinsicContentSize().height
let w: CGFloat = backButton.intrinsicContentSize().width
let inset: CGFloat = MaterialDevice.landscape ? item.landscapeInset : item.portraitInset
// leftControls
......@@ -277,7 +281,7 @@ public class NavigationBar : UINavigationBar {
b.contentEdgeInsets.top = 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))
}
......@@ -290,11 +294,12 @@ public class NavigationBar : UINavigationBar {
}
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!.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 = []
// TitleView alignment.
......@@ -334,13 +339,13 @@ public class NavigationBar : UINavigationBar {
b.contentEdgeInsets.top = 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))
}
// The spacer moves the UIBarButtonItems to the edge of the UINavigationBar.
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = inset + contentInset.left
spacer.width = inset + contentInset.right
n.append(spacer)
item.rightBarButtonItems = n.reverse()
......@@ -362,6 +367,7 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil
backgroundColor = MaterialColor.white
depth = .Depth1
contentInset = UIEdgeInsetsMake(2, 6, 2, 6)
prepareBackButton()
}
......@@ -375,9 +381,7 @@ public class NavigationBar : UINavigationBar {
/// Prepares the UINavigationItem for layout and sizing.
internal func prepareItem(item: UINavigationItem) {
if nil == item.title {
item.title = ""
}
item.title = ""
}
}
......
......@@ -64,16 +64,6 @@ public class NavigationController : UINavigationController {
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.
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