Commit d56c1135 by Daniel Dahan

adjusting NavigationBar alignment

parent 28bbe4cb
......@@ -13,7 +13,7 @@
9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* SearchListViewController.swift */; };
9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; };
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 */; };
9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */; };
9663F94E1C7A74EA00AF0965 /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */; };
......@@ -45,7 +45,7 @@
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>"; };
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>"; };
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>"; };
......@@ -88,7 +88,7 @@
isa = PBXGroup;
children = (
9663F9311C7A744600AF0965 /* AppDelegate.swift */,
9663F9471C7A749400AF0965 /* AppNavigationBarViewController.swift */,
9663F9471C7A749400AF0965 /* AppNavigationController.swift */,
9663F9491C7A74B500AF0965 /* AppSearchBarViewController.swift */,
9663F94B1C7A74C700AF0965 /* AppMenuViewController.swift */,
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */,
......@@ -179,7 +179,7 @@
9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */,
96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */,
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */,
9663F9481C7A749400AF0965 /* AppNavigationBarViewController.swift in Sources */,
9663F9481C7A749400AF0965 /* AppNavigationController.swift in Sources */,
9663F9341C7A744600AF0965 /* SearchListViewController.swift in Sources */,
9663F94C1C7A74C700AF0965 /* AppMenuViewController.swift in Sources */,
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */,
......
......@@ -37,45 +37,14 @@ import UIKit
import Material
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() {
super.viewDidLoad()
prepareMenuButton()
prepareSearchButton()
navigationBar.leftControls = [menuButton]
navigationBar.rightControls = [searchButton]
navigationBar.statusBarStyle = .LightContent
navigationBar.tintColor = MaterialColor.white
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 {
......
......@@ -32,12 +32,20 @@ import UIKit
import Material
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.
private lazy var collectionView: MaterialCollectionView = MaterialCollectionView()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareMenuButton()
prepareSearchButton()
prepareCollectionView()
}
......@@ -51,10 +59,12 @@ class FeedViewController: UIViewController {
collectionView.reloadData()
}
/// Handler for menuButton.
internal func handleMenuButton() {
sideNavigationViewController?.toggleLeftView()
// sideNavigationViewController?.toggleLeftView()
}
/// Handler for searchButton.
internal func handleSearchButton() {
print("handled")
}
......@@ -75,6 +85,29 @@ class FeedViewController: UIViewController {
navigationItem.titleLabel = titleLabel
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
......
......@@ -80,6 +80,16 @@ class MessagesViewController: UIViewController {
navigationItem.titleLabel = titleLabel
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.
......
/*
* 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.
*
* 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.
*
* 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.
*
* Redistribution and use in source and binary forms, with or without
......
......@@ -133,8 +133,6 @@ public class NavigationBar : UINavigationBar {
if nil == backButtonImage {
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 {
}
}
public override func layoutSubviews() {
super.layoutSubviews()
public func layoutNavigationItem(item: UINavigationItem) {
grid.views = []
grid.axis.columns = Int(width / 48)
backItem?.title = ""
// 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
let g: CGFloat = width / CGFloat(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)
var columns: Int = grid.axis.columns
// leftControls
if let v: Array<UIControl> = item.leftControls {
for c in v {
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
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 nil == v.titleView {
v.titleView = UIView()
v.titleView!.backgroundColor = nil
v.titleView!.grid.axis.direction = .Vertical
if let d: UILabel = item.detailLabel {
t.grid.rows = 2
t.font = t.font.fontWithSize(17)
d.grid.rows = 2
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 = []
// 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
}
}
c.grid.columns = 0 == g ? 1 : Int(ceil(c.intrinsicContentSize().width / g))
columns -= c.grid.columns
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 {
backButtonImage = nil
backgroundColor = MaterialColor.white
depth = .Depth1
spacingPreset = .Spacing2
contentInset = UIEdgeInsetsMake(8, 0, 8, 0)
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
}
/// Prepares the visualLayer property.
......@@ -498,9 +488,9 @@ public class NavigationBar : UINavigationBar {
}
/// 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.
public var leftControls: Array<UIControl>?
......@@ -508,66 +498,59 @@ public class NavigationBarControls {
public var rightControls: Array<UIControl>?
}
public extension UINavigationBar {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
private var NavigationItemLabelsKey: UInt8 = 0
public class NavigationItemLabels {
/// Title label.
public var titleLabel: UILabel?
/// Detail label.
public var detailLabel: UILabel?
}
public extension UINavigationItem {
/// NavigationBarControls reference.
public internal(set) var controls: NavigationBarControls {
public internal(set) var labels: NavigationItemLabels {
get {
return MaterialAssociatedObject(self, key: &NavigationBarKey) {
return NavigationBarControls()
return MaterialAssociatedObject(self, key: &NavigationItemLabelsKey) {
return NavigationItemLabels()
}
}
set(value) {
MaterialAssociateObject(self, key: &NavigationBarKey, value: value)
}
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return grid.contentInsetPreset
}
set(value) {
grid.contentInsetPreset = value
MaterialAssociateObject(self, key: &NavigationItemLabelsKey, value: value)
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
/// Title Label.
public var titleLabel: UILabel? {
get {
return grid.contentInset
return labels.titleLabel
}
set(value) {
grid.contentInset = value
labels.titleLabel = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing {
/// Detail Label.
public var detailLabel: UILabel? {
get {
return grid.spacingPreset
return labels.detailLabel
}
set(value) {
grid.spacingPreset = value
labels.detailLabel = value
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
/// NavigationBarControls reference.
public internal(set) var controls: NavigationItemControls {
get {
return grid.spacing
return MaterialAssociatedObject(self, key: &NavigationItemControlsKey) {
return NavigationItemControls()
}
}
set(value) {
grid.spacing = value
MaterialAssociateObject(self, key: &NavigationItemControlsKey, value: value)
}
}
......@@ -584,12 +567,12 @@ public extension UINavigationBar {
}
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12
// c.append(spacer)
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = 0
c.append(spacer)
controls.leftControls = value
topItem?.leftBarButtonItems = c.reverse()
leftBarButtonItems = c.reverse()
}
}
......@@ -606,57 +589,64 @@ public extension UINavigationBar {
}
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12
// c.append(spacer)
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = 0
c.append(spacer)
controls.rightControls = value
topItem?.rightBarButtonItems = c.reverse()
rightBarButtonItems = c.reverse()
}
}
}
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
private var NavigationItemKey: UInt8 = 0
public class NavigationItemLabels {
/// Title label.
public var titleLabel: UILabel?
public extension UINavigationBar {
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
}
}
/// Detail label.
public var detailLabel: UILabel?
}
public extension UINavigationItem {
/// NavigationBarControls reference.
public internal(set) var labels: NavigationItemLabels {
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return MaterialAssociatedObject(self, key: &NavigationItemKey) {
return NavigationItemLabels()
}
return grid.contentInsetPreset
}
set(value) {
MaterialAssociateObject(self, key: &NavigationItemKey, value: value)
grid.contentInsetPreset = value
}
}
/// Title Label.
public var titleLabel: UILabel? {
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
get {
return labels.titleLabel
return grid.contentInset
}
set(value) {
labels.titleLabel = value
grid.contentInset = value
}
}
/// Detail Label.
public var detailLabel: UILabel? {
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing {
get {
return labels.detailLabel
return grid.spacingPreset
}
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 @@
import UIKit
public class NavigationController : UINavigationController, UINavigationBarDelegate {
public private(set) lazy var backButton: FlatButton = FlatButton()
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
......@@ -45,9 +46,49 @@ public class NavigationController : UINavigationController, UINavigationBarDeleg
setViewControllers([rootViewController], animated: false)
}
public override func viewDidLoad() {
super.viewDidLoad()
prepareBackButton()
interactivePopGestureRecognizer?.delegate = nil
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
interactivePopGestureRecognizer?.delegate = nil
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