Commit 8ce9ef8a by Daniel Dahan

Added titleLabel and detailLabel to NavigationBar

parent 9b9bd858
......@@ -72,13 +72,19 @@ class FeedViewController: UIViewController {
prepareMenuButton()
prepareSearchButton()
// navigationItem.title = "Feed"
let titleLabel: UILabel = UILabel()
titleLabel.text = "Material"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
let detailLabel: UILabel = UILabel()
detailLabel.text = "Build Beautiful Software"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
var label: UILabel = UILabel()
label.text = "Daniel"
navigationItem.titleView?.addSubview(label)
navigationController?.navigationBar.leftControls = [menuButton]
navigationController?.navigationBar.rightControls = [searchButton]
navigationController?.navigationBar.statusBarStyle = .LightContent
......
......@@ -46,8 +46,8 @@ class InboxViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareView()
prepareTableView()
}
......@@ -68,7 +68,18 @@ class InboxViewController: UIViewController {
private func prepareView() {
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.
......
......@@ -46,8 +46,8 @@ class MessagesViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareView()
prepareTableView()
}
......@@ -68,7 +68,18 @@ class MessagesViewController: UIViewController {
private func prepareView() {
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.
......
......@@ -374,53 +374,87 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() {
super.layoutSubviews()
if 1 < width {
// Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
grid.views = []
grid.axis.columns = Int(width / 48)
var columns: Int = grid.axis.columns
// leftControls
if let v: Array<UIControl> = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
columns -= c.grid.columns
grid.views?.append(c)
// Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
grid.views = []
grid.axis.columns = Int(width / 48)
var columns: Int = grid.axis.columns
// leftControls
if let v: Array<UIControl> = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
columns -= c.grid.columns
grid.views?.append(c)
}
if nil == topItem?.titleView {
topItem?.titleView = MaterialView()
topItem?.titleView?.backgroundColor = nil
}
if let v: UINavigationItem = topItem {
if nil == v.titleView {
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()
}
grid.views?.append(topItem!.titleView!)
// rightControls
if let v: Array<UIControl> = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
columns -= c.grid.columns
grid.views?.append(c)
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
}
}
topItem?.titleView?.grid.columns = columns
// rightControls?.first?.grid.offset.columns = columns
grid.reloadLayout()
grid.views?.append(v.titleView!)
}
// rightControls
if let v: Array<UIControl> = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
columns -= c.grid.columns
grid.views?.append(c)
}
}
topItem?.titleView?.grid.columns = columns
grid.reloadLayout()
topItem?.titleView?.grid.reloadLayout()
}
}
......@@ -438,7 +472,9 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil
backgroundColor = MaterialColor.white
depth = .Depth1
contentInsetPreset = .None
spacingPreset = .Spacing2
contentInsetPreset = .Square2
contentInset.left = 100
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
......@@ -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
public class NavigationBarControls {
......@@ -480,6 +516,20 @@ public class NavigationBarControls {
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 {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
......@@ -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