Commit d56c1135 by Daniel Dahan

adjusting NavigationBar alignment

parent 28bbe4cb
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* SearchListViewController.swift */; }; 9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* SearchListViewController.swift */; };
9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; }; 9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; };
9663F93C1C7A744600AF0965 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */; }; 9663F93C1C7A744600AF0965 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */; };
9663F9481C7A749400AF0965 /* AppNavigationBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9471C7A749400AF0965 /* AppNavigationBarViewController.swift */; }; 9663F9481C7A749400AF0965 /* AppNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9471C7A749400AF0965 /* AppNavigationController.swift */; };
9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */; }; 9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */; };
9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */; }; 9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */; };
9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; }; 9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; };
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
9663F9381C7A744600AF0965 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 9663F9381C7A744600AF0965 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9663F93B1C7A744600AF0965 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 9663F93B1C7A744600AF0965 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9663F93D1C7A744600AF0965 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9663F93D1C7A744600AF0965 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9663F9471C7A749400AF0965 /* AppNavigationBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppNavigationBarViewController.swift; sourceTree = "<group>"; }; 9663F9471C7A749400AF0965 /* AppNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppNavigationController.swift; sourceTree = "<group>"; };
9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSearchBarViewController.swift; sourceTree = "<group>"; }; 9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSearchBarViewController.swift; sourceTree = "<group>"; };
9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMenuViewController.swift; sourceTree = "<group>"; }; 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMenuViewController.swift; sourceTree = "<group>"; };
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; }; 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppLeftViewController.swift; sourceTree = "<group>"; };
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9663F9311C7A744600AF0965 /* AppDelegate.swift */, 9663F9311C7A744600AF0965 /* AppDelegate.swift */,
9663F9471C7A749400AF0965 /* AppNavigationBarViewController.swift */, 9663F9471C7A749400AF0965 /* AppNavigationController.swift */,
9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */, 9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */,
9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */, 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */,
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */, 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */,
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */, 9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */,
96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */, 96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */,
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */, 9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */,
9663F9481C7A749400AF0965 /* AppNavigationBarViewController.swift in Sources */, 9663F9481C7A749400AF0965 /* AppNavigationController.swift in Sources */,
9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */, 9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */,
9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */, 9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */,
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */, 9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */,
......
...@@ -37,45 +37,14 @@ import UIKit ...@@ -37,45 +37,14 @@ import UIKit
import Material import Material
class AppNavigationController : NavigationController { class AppNavigationController : NavigationController {
/// Menu button at the top left of the navigation bar.
private lazy var menuButton: FlatButton = FlatButton()
/// Search button at the top left of the navigation bar.
private lazy var searchButton: FlatButton = FlatButton()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareMenuButton()
prepareSearchButton()
navigationBar.leftControls = [menuButton]
navigationBar.rightControls = [searchButton]
navigationBar.statusBarStyle = .LightContent navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
} }
/// Prepares the menuButton.
private func prepareMenuButton() {
let image: UIImage? = UIImage(named: "ic_menu_white")
menuButton.pulseScale = false
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
}
/// Prepares the searchButton.
private func prepareSearchButton() {
// Search button.
let image: UIImage? = UIImage(named: "ic_search_white")
searchButton.pulseScale = false
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
}
} }
//class AppNavigationBarViewController: NavigationBarViewController { //class AppNavigationBarViewController: NavigationBarViewController {
......
...@@ -32,12 +32,20 @@ import UIKit ...@@ -32,12 +32,20 @@ import UIKit
import Material import Material
class FeedViewController: UIViewController { class FeedViewController: UIViewController {
/// Menu button at the top left of the navigation bar.
private lazy var menuButton: FlatButton = FlatButton()
/// Search button at the top left of the navigation bar.
private lazy var searchButton: FlatButton = FlatButton()
/// MaterialCollectionView. /// MaterialCollectionView.
private lazy var collectionView: MaterialCollectionView = MaterialCollectionView() private lazy var collectionView: MaterialCollectionView = MaterialCollectionView()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareMenuButton()
prepareSearchButton()
prepareCollectionView() prepareCollectionView()
} }
...@@ -51,10 +59,12 @@ class FeedViewController: UIViewController { ...@@ -51,10 +59,12 @@ class FeedViewController: UIViewController {
collectionView.reloadData() collectionView.reloadData()
} }
/// Handler for menuButton.
internal func handleMenuButton() { internal func handleMenuButton() {
sideNavigationViewController?.toggleLeftView() // sideNavigationViewController?.toggleLeftView()
} }
/// Handler for searchButton.
internal func handleSearchButton() { internal func handleSearchButton() {
print("handled") print("handled")
} }
...@@ -75,6 +85,29 @@ class FeedViewController: UIViewController { ...@@ -75,6 +85,29 @@ class FeedViewController: UIViewController {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel navigationItem.detailLabel = detailLabel
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [searchButton]
}
/// Prepares the menuButton.
private func prepareMenuButton() {
let image: UIImage? = UIImage(named: "ic_menu_white")
menuButton.pulseScale = false
menuButton.pulseColor = MaterialColor.white
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
}
/// Prepares the searchButton.
private func prepareSearchButton() {
// Search button.
let image: UIImage? = UIImage(named: "ic_search_white")
searchButton.pulseScale = false
searchButton.pulseColor = MaterialColor.white
searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
} }
/// Prepares the collectionView /// Prepares the collectionView
......
...@@ -80,6 +80,16 @@ class MessagesViewController: UIViewController { ...@@ -80,6 +80,16 @@ class MessagesViewController: UIViewController {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel navigationItem.detailLabel = detailLabel
let image: UIImage? = UIImage(named: "ic_share_white")?.imageWithRenderingMode(.AlwaysTemplate)
let shareButton: FlatButton = FlatButton()
shareButton.pulseScale = false
shareButton.pulseColor = MaterialColor.grey.base
shareButton.tintColor = MaterialColor.grey.base
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
navigationItem.rightControls = [shareButton]
} }
/// Prepares the items Array. /// Prepares the items Array.
......
/* /*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
/* /*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
/* /*
* Copyright (C) 2015 - 20spacing, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. * Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
...@@ -133,8 +133,6 @@ public class NavigationBar : UINavigationBar { ...@@ -133,8 +133,6 @@ public class NavigationBar : UINavigationBar {
if nil == backButtonImage { if nil == backButtonImage {
backButtonImage = UIImage(named: "ic_arrow_back_white", inBundle: NSBundle(identifier: "io.cosmicmind.Material"), compatibleWithTraitCollection: nil) backButtonImage = UIImage(named: "ic_arrow_back_white", inBundle: NSBundle(identifier: "io.cosmicmind.Material"), compatibleWithTraitCollection: nil)
} }
backIndicatorImage = backButtonImage
backIndicatorTransitionMaskImage = backButtonImage
} }
} }
...@@ -371,85 +369,79 @@ public class NavigationBar : UINavigationBar { ...@@ -371,85 +369,79 @@ public class NavigationBar : UINavigationBar {
} }
} }
public override func layoutSubviews() { public func layoutNavigationItem(item: UINavigationItem) {
super.layoutSubviews() grid.views = []
grid.axis.columns = Int(width / 48)
backItem?.title = "" let g: CGFloat = width / CGFloat(grid.axis.columns)
// 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 var columns: Int = grid.axis.columns
if let v: Array<UIControl> = leftControls {
for c in v { // leftControls
let w: CGFloat = c.intrinsicContentSize().width if let v: Array<UIControl> = item.leftControls {
if let b: UIButton = c as? UIButton { for c in v {
b.contentEdgeInsets = UIEdgeInsetsZero 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)
} }
c.grid.columns = 0 == g ? 1 : Int(ceil(c.intrinsicContentSize().width / g))
columns -= c.grid.columns
grid.views?.append(c)
} }
}
if nil == item.titleView {
item.titleView = UIView()
item.titleView!.backgroundColor = nil
item.titleView!.grid.axis.direction = .Vertical
}
item.titleView!.grid.views = []
// TitleView alignment.
if let t: UILabel = item.titleLabel {
item.titleView!.addSubview(t)
item.titleView!.grid.views?.append(t)
if let v: UINavigationItem = topItem { if let d: UILabel = item.detailLabel {
if nil == v.titleView { t.grid.rows = 2
v.titleView = UIView() t.font = t.font.fontWithSize(17)
v.titleView!.backgroundColor = nil d.grid.rows = 2
v.titleView!.grid.axis.direction = .Vertical d.font = d.font.fontWithSize(12)
item.titleView!.addSubview(d)
item.titleView!.grid.views?.append(d)
item.titleView!.grid.axis.rows = 3
item.titleView!.grid.spacing = -8
item.titleView!.grid.contentInset.top = -8
} else {
t.grid.rows = 1
t.font = t.font?.fontWithSize(20)
item.titleView!.grid.axis.rows = 1
item.titleView!.grid.spacing = 0
item.titleView!.grid.contentInset.top = 0
}
}
grid.views?.append(item.titleView!)
// rightControls
if let v: Array<UIControl> = item.rightControls {
for c in v {
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
} }
v.titleView!.grid.views = [] c.grid.columns = 0 == g ? 1 : Int(ceil(c.intrinsicContentSize().width / g))
columns -= c.grid.columns
// 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(c)
} }
// 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()
} }
item.titleView!.grid.columns = columns
grid.reloadLayout()
item.titleView?.grid.reloadLayout()
} }
/** /**
...@@ -466,10 +458,8 @@ public class NavigationBar : UINavigationBar { ...@@ -466,10 +458,8 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
spacingPreset = .Spacing2
contentInset = UIEdgeInsetsMake(8, 0, 8, 0) contentInset = UIEdgeInsetsMake(8, 0, 8, 0)
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
} }
/// Prepares the visualLayer property. /// Prepares the visualLayer property.
...@@ -498,9 +488,9 @@ public class NavigationBar : UINavigationBar { ...@@ -498,9 +488,9 @@ public class NavigationBar : UINavigationBar {
} }
/// A memory reference to the NavigationBarControls instance for UINavigationBar extensions. /// A memory reference to the NavigationBarControls instance for UINavigationBar extensions.
private var NavigationBarKey: UInt8 = 0 private var NavigationItemControlsKey: UInt8 = 0
public class NavigationBarControls { public class NavigationItemControls {
/// Left controls. /// Left controls.
public var leftControls: Array<UIControl>? public var leftControls: Array<UIControl>?
...@@ -508,66 +498,59 @@ public class NavigationBarControls { ...@@ -508,66 +498,59 @@ public class NavigationBarControls {
public var rightControls: Array<UIControl>? public var rightControls: Array<UIControl>?
} }
public extension UINavigationBar { /// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
/// Device status bar style. private var NavigationItemLabelsKey: UInt8 = 0
public var statusBarStyle: UIStatusBarStyle {
get { public class NavigationItemLabels {
return MaterialDevice.statusBarStyle /// Title label.
} public var titleLabel: UILabel?
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// Detail label.
public var detailLabel: UILabel?
}
public extension UINavigationItem {
/// NavigationBarControls reference. /// NavigationBarControls reference.
public internal(set) var controls: NavigationBarControls { public internal(set) var labels: NavigationItemLabels {
get { get {
return MaterialAssociatedObject(self, key: &NavigationBarKey) { return MaterialAssociatedObject(self, key: &NavigationItemLabelsKey) {
return NavigationBarControls() return NavigationItemLabels()
} }
} }
set(value) { set(value) {
MaterialAssociateObject(self, key: &NavigationBarKey, value: value) MaterialAssociateObject(self, key: &NavigationItemLabelsKey, value: value)
}
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return grid.contentInsetPreset
}
set(value) {
grid.contentInsetPreset = value
} }
} }
/// A wrapper around grid.contentInset. /// Title Label.
public var contentInset: UIEdgeInsets { public var titleLabel: UILabel? {
get { get {
return grid.contentInset return labels.titleLabel
} }
set(value) { set(value) {
grid.contentInset = value labels.titleLabel = value
} }
} }
/// A preset wrapper around spacing. /// Detail Label.
public var spacingPreset: MaterialSpacing { public var detailLabel: UILabel? {
get { get {
return grid.spacingPreset return labels.detailLabel
} }
set(value) { set(value) {
grid.spacingPreset = value labels.detailLabel = value
} }
} }
/// A wrapper around grid.spacing. /// NavigationBarControls reference.
public var spacing: CGFloat { public internal(set) var controls: NavigationItemControls {
get { get {
return grid.spacing return MaterialAssociatedObject(self, key: &NavigationItemControlsKey) {
return NavigationItemControls()
}
} }
set(value) { set(value) {
grid.spacing = value MaterialAssociateObject(self, key: &NavigationItemControlsKey, value: value)
} }
} }
...@@ -584,12 +567,12 @@ public extension UINavigationBar { ...@@ -584,12 +567,12 @@ public extension UINavigationBar {
} }
} }
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil) let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12 spacer.width = 0
// c.append(spacer) c.append(spacer)
controls.leftControls = value controls.leftControls = value
topItem?.leftBarButtonItems = c.reverse() leftBarButtonItems = c.reverse()
} }
} }
...@@ -606,57 +589,64 @@ public extension UINavigationBar { ...@@ -606,57 +589,64 @@ public extension UINavigationBar {
} }
} }
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil) let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12 spacer.width = 0
// c.append(spacer) c.append(spacer)
controls.rightControls = value controls.rightControls = value
topItem?.rightBarButtonItems = c.reverse() rightBarButtonItems = c.reverse()
} }
} }
} }
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions. public extension UINavigationBar {
private var NavigationItemKey: UInt8 = 0 /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
public class NavigationItemLabels { get {
/// Title label. return MaterialDevice.statusBarStyle
public var titleLabel: UILabel? }
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// Detail label. /// A preset wrapper around contentInset.
public var detailLabel: UILabel? public var contentInsetPreset: MaterialEdgeInset {
}
public extension UINavigationItem {
/// NavigationBarControls reference.
public internal(set) var labels: NavigationItemLabels {
get { get {
return MaterialAssociatedObject(self, key: &NavigationItemKey) { return grid.contentInsetPreset
return NavigationItemLabels()
}
} }
set(value) { set(value) {
MaterialAssociateObject(self, key: &NavigationItemKey, value: value) grid.contentInsetPreset = value
} }
} }
/// Title Label. /// A wrapper around grid.contentInset.
public var titleLabel: UILabel? { public var contentInset: UIEdgeInsets {
get { get {
return labels.titleLabel return grid.contentInset
} }
set(value) { set(value) {
labels.titleLabel = value grid.contentInset = value
} }
} }
/// Detail Label. /// A preset wrapper around spacing.
public var detailLabel: UILabel? { public var spacingPreset: MaterialSpacing {
get { get {
return labels.detailLabel return grid.spacingPreset
} }
set(value) { set(value) {
labels.detailLabel = value grid.spacingPreset = value
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return grid.spacing
}
set(value) {
grid.spacing = value
} }
} }
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
import UIKit import UIKit
public class NavigationController : UINavigationController, UINavigationBarDelegate { public class NavigationController : UINavigationController, UINavigationBarDelegate {
public private(set) lazy var backButton: FlatButton = FlatButton()
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
...@@ -45,9 +46,49 @@ public class NavigationController : UINavigationController, UINavigationBarDeleg ...@@ -45,9 +46,49 @@ public class NavigationController : UINavigationController, UINavigationBarDeleg
setViewControllers([rootViewController], animated: false) setViewControllers([rootViewController], animated: false)
} }
public override func viewDidLoad() {
super.viewDidLoad()
prepareBackButton()
interactivePopGestureRecognizer?.delegate = nil
}
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
interactivePopGestureRecognizer?.delegate = nil
navigationBar.layoutSubviews() navigationBar.layoutSubviews()
} }
public override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if let v: UINavigationItem = navigationBar.topItem {
v.title = ""
(navigationBar as? NavigationBar)?.layoutNavigationItem(v)
}
}
public func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
item.title = ""
item.setHidesBackButton(true, animated: false)
return true
}
public func navigationBar(navigationBar: UINavigationBar, didPushItem item: UINavigationItem) {
if let v: NavigationBar = navigationBar as? NavigationBar {
item.leftControls = [backButton]
v.layoutNavigationItem(item)
}
}
internal func handleBackButton() {
popViewControllerAnimated(true)
}
private func prepareBackButton() {
if let v: NavigationBar = navigationBar as? NavigationBar {
backButton.pulseScale = false
backButton.pulseColor = MaterialColor.white
backButton.setImage(v.backButtonImage, forState: .Normal)
backButton.setImage(v.backButtonImage, forState: .Highlighted)
backButton.addTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
}
}
} }
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