Commit 8ce9ef8a by Daniel Dahan

Added titleLabel and detailLabel to NavigationBar

parent 9b9bd858
...@@ -72,12 +72,18 @@ class FeedViewController: UIViewController { ...@@ -72,12 +72,18 @@ class FeedViewController: UIViewController {
prepareMenuButton() prepareMenuButton()
prepareSearchButton() prepareSearchButton()
// navigationItem.title = "Feed" let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
var label: UILabel = UILabel() let detailLabel: UILabel = UILabel()
label.text = "Daniel" detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
navigationItem.titleView?.addSubview(label) navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
navigationController?.navigationBar.leftControls = [menuButton] navigationController?.navigationBar.leftControls = [menuButton]
navigationController?.navigationBar.rightControls = [searchButton] navigationController?.navigationBar.rightControls = [searchButton]
......
...@@ -46,8 +46,8 @@ class InboxViewController: UIViewController { ...@@ -46,8 +46,8 @@ class InboxViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
prepareItems() prepareItems()
prepareView()
prepareTableView() prepareTableView()
} }
...@@ -68,7 +68,18 @@ class InboxViewController: UIViewController { ...@@ -68,7 +68,18 @@ class InboxViewController: UIViewController {
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
navigationItem.title = "Inbox" let titleLabel: UILabel = UILabel()
titleLabel.text = "Inbox"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
let detailLabel: UILabel = UILabel()
detailLabel.text = "\(items.count) Contacts"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
} }
/// Prepares the items Array. /// Prepares the items Array.
......
...@@ -46,8 +46,8 @@ class MessagesViewController: UIViewController { ...@@ -46,8 +46,8 @@ class MessagesViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
prepareItems() prepareItems()
prepareView()
prepareTableView() prepareTableView()
} }
...@@ -68,7 +68,18 @@ class MessagesViewController: UIViewController { ...@@ -68,7 +68,18 @@ class MessagesViewController: UIViewController {
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
navigationItem.title = "Messages" let titleLabel: UILabel = UILabel()
titleLabel.text = "Messages"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
let detailLabel: UILabel = UILabel()
detailLabel.text = "\(items.count) Messages"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
} }
/// Prepares the items Array. /// Prepares the items Array.
......
...@@ -374,7 +374,6 @@ public class NavigationBar : UINavigationBar { ...@@ -374,7 +374,6 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if 1 < width {
// Size of single grid column. // Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) { if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
grid.views = [] grid.views = []
...@@ -396,11 +395,47 @@ public class NavigationBar : UINavigationBar { ...@@ -396,11 +395,47 @@ public class NavigationBar : UINavigationBar {
} }
} }
if nil == topItem?.titleView { if let v: UINavigationItem = topItem {
topItem?.titleView = MaterialView() if nil == v.titleView {
topItem?.titleView?.backgroundColor = nil if nil != backItem {
let button: FlatButton = FlatButton()
button.setImage(backButtonImage, forState: .Normal)
button.setImage(backButtonImage, forState: .Highlighted)
v.backBarButtonItem = UIBarButtonItem(customView: button)
backItem?.title = ""
}
v.titleView = UIView()
}
v.titleView!.backgroundColor = nil
v.titleView!.grid.axis.direction = .Vertical
v.titleView!.grid.views = []
// TitleView alignment.
if let t: UILabel = v.titleLabel {
v.titleView!.addSubview(t)
v.titleView!.grid.views?.append(t)
if let d: UILabel = v.detailLabel {
v.titleView!.addSubview(d)
v.titleView!.grid.views?.append(d)
t.grid.rows = 2
t.font = t.font.fontWithSize(17)
d.grid.rows = 2
d.font = d.font.fontWithSize(12)
v.titleView!.grid.axis.rows = 3
v.titleView!.grid.spacing = -8
v.titleView!.grid.contentInset.top = -8
} else {
t.grid.rows = 1
t.font = t.font?.fontWithSize(20)
v.titleView!.grid.axis.rows = 1
v.titleView!.grid.spacing = 0
v.titleView!.grid.contentInset.top = 0
}
}
grid.views?.append(v.titleView!)
} }
grid.views?.append(topItem!.titleView!)
// rightControls // rightControls
if let v: Array<UIControl> = rightControls { if let v: Array<UIControl> = rightControls {
...@@ -417,10 +452,9 @@ public class NavigationBar : UINavigationBar { ...@@ -417,10 +452,9 @@ public class NavigationBar : UINavigationBar {
} }
} }
topItem?.titleView?.grid.columns = columns topItem?.titleView?.grid.columns = columns
// rightControls?.first?.grid.offset.columns = columns
grid.reloadLayout() grid.reloadLayout()
} topItem?.titleView?.grid.reloadLayout()
} }
} }
...@@ -438,7 +472,9 @@ public class NavigationBar : UINavigationBar { ...@@ -438,7 +472,9 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
contentInsetPreset = .None spacingPreset = .Spacing2
contentInsetPreset = .Square2
contentInset.left = 100
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)] titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default) setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact) setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
...@@ -469,7 +505,7 @@ public class NavigationBar : UINavigationBar { ...@@ -469,7 +505,7 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// A memory reference to the Grid instance for UIView extensions. /// A memory reference to the NavigationBarControls instance for UINavigationBar extensions.
private var NavigationBarKey: UInt8 = 0 private var NavigationBarKey: UInt8 = 0
public class NavigationBarControls { public class NavigationBarControls {
...@@ -480,6 +516,20 @@ public class NavigationBarControls { ...@@ -480,6 +516,20 @@ public class NavigationBarControls {
public var rightControls: Array<UIControl>? public var rightControls: Array<UIControl>?
} }
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
private var NavigationItemKey: UInt8 = 0
public class NavigationItemLabels {
/// Title view.
public var titleView: UIView?
/// Title label.
public var titleLabel: UILabel?
/// Detail label.
public var detailLabel: UILabel?
}
public extension UINavigationBar { public extension UINavigationBar {
/// Device status bar style. /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle { public var statusBarStyle: UIStatusBarStyle {
...@@ -579,3 +629,37 @@ public extension UINavigationBar { ...@@ -579,3 +629,37 @@ public extension UINavigationBar {
} }
} }
} }
public extension UINavigationItem {
/// NavigationBarControls reference.
public internal(set) var labels: NavigationItemLabels {
get {
return MaterialAssociatedObject(self, key: &NavigationItemKey) {
return NavigationItemLabels()
}
}
set(value) {
MaterialAssociateObject(self, key: &NavigationItemKey, value: value)
}
}
/// Title Label.
public var titleLabel: UILabel? {
get {
return labels.titleLabel
}
set(value) {
labels.titleLabel = value
}
}
/// Detail Label.
public var detailLabel: UILabel? {
get {
return labels.detailLabel
}
set(value) {
labels.detailLabel = value
}
}
}
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