Commit 9b9bd858 by Daniel Dahan

titleView now added to NavigationBar

parent 39244b57
......@@ -20,6 +20,7 @@
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F94F1C7A74FC00AF0965 /* AppRightViewController.swift */; };
9663F9521C7A751D00AF0965 /* FeedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9511C7A751D00AF0965 /* FeedViewController.swift */; };
96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC08871C7FEBD60034FF84 /* InboxViewController.swift */; };
96FC37D31C8CE1290040A569 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96FC37D21C8CE1290040A569 /* MessagesViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -51,6 +52,7 @@
9663F94F1C7A74FC00AF0965 /* AppRightViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppRightViewController.swift; sourceTree = "<group>"; };
9663F9511C7A751D00AF0965 /* FeedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedViewController.swift; sourceTree = "<group>"; };
96CC08871C7FEBD60034FF84 /* InboxViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InboxViewController.swift; sourceTree = "<group>"; };
96FC37D21C8CE1290040A569 /* MessagesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -92,8 +94,9 @@
9663F94D1C7A74EA00AF0965 /* AppLeftViewController.swift */,
9663F94F1C7A74FC00AF0965 /* AppRightViewController.swift */,
9663F9331C7A744600AF0965 /* SearchListViewController.swift */,
96CC08871C7FEBD60034FF84 /* InboxViewController.swift */,
9663F9511C7A751D00AF0965 /* FeedViewController.swift */,
96CC08871C7FEBD60034FF84 /* InboxViewController.swift */,
96FC37D21C8CE1290040A569 /* MessagesViewController.swift */,
9663F9381C7A744600AF0965 /* Assets.xcassets */,
9663F93A1C7A744600AF0965 /* LaunchScreen.storyboard */,
9663F93D1C7A744600AF0965 /* Info.plist */,
......@@ -172,6 +175,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96FC37D31C8CE1290040A569 /* MessagesViewController.swift in Sources */,
9663F94A1C7A74B500AF0965 /* AppSearchBarViewController.swift in Sources */,
96CC08881C7FEBD60034FF84 /* InboxViewController.swift in Sources */,
9663F9501C7A74FC00AF0965 /* AppRightViewController.swift in Sources */,
......
......@@ -72,7 +72,13 @@ class FeedViewController: UIViewController {
prepareMenuButton()
prepareSearchButton()
navigationItem.title = "Feed"
// navigationItem.title = "Feed"
var label: UILabel = UILabel()
label.text = "Daniel"
navigationItem.titleView?.addSubview(label)
navigationController?.navigationBar.leftControls = [menuButton]
navigationController?.navigationBar.rightControls = [searchButton]
navigationController?.navigationBar.statusBarStyle = .LightContent
......@@ -245,7 +251,6 @@ extension FeedViewController: MaterialCollectionViewDataSource {
extension FeedViewController: MaterialCollectionViewDelegate {
/// Executed when an item is selected.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// print(indexPath)
navigationController?.pushViewController(InboxViewController(), animated: true)
}
}
\ No newline at end of file
......@@ -154,4 +154,9 @@ extension InboxViewController: UITableViewDelegate {
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 48
}
/// Did select table.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
navigationController?.pushViewController(MessagesViewController(), animated: true)
}
}
/*
* 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
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
private struct Item {
var text: String
var detail: String
var image: UIImage?
}
class MessagesViewController: UIViewController {
/// A tableView used to display Bond entries.
private let tableView: UITableView = UITableView()
/// A list of all the Author Bond types.
private var items: Array<Item> = Array<Item>()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareTableView()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
sideNavigationViewController?.enabled = false
}
/**
Handles the search button click, which opens the
SideNavigationViewController.
*/
func handleSearchButton() {
sideNavigationViewController?.openRightView()
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.white
navigationItem.title = "Messages"
}
/// Prepares the items Array.
private func prepareItems() {
items.append(Item(text: "Summer BBQ", detail: "Wish I could come, but I am out of town this weekend.", image: UIImage(named: "Profile1")))
items.append(Item(text: "Birthday gift", detail: "Have any ideas about what we should get Heidi for her birthday?", image: UIImage(named: "Profile2")))
items.append(Item(text: "Brunch this weekend?", detail: "I'll be in your neighborhood doing errands this weekend.", image: UIImage(named: "Profile3")))
items.append(Item(text: "Giants game", detail: "Are we on this weekend for the game?", image: UIImage(named: "Profile4")))
items.append(Item(text: "Recipe to try", detail: "We should eat this: Squash, Corn and tomatillo Tacos.", image: UIImage(named: "Profile5")))
items.append(Item(text: "Interview", detail: "The candidate will be arriving at 11:30, are you free?", image: UIImage(named: "Profile6")))
items.append(Item(text: "Book recommendation", detail: "I found the book title, Surely You’re Joking, Mr. Feynman!", image: UIImage(named: "Profile7")))
items.append(Item(text: "Oui oui", detail: "Do you have Paris recommendations? Have you ever been?", image: UIImage(named: "Profile8")))
}
/// Prepares the tableView.
private func prepareTableView() {
tableView.registerClass(MaterialTableViewCell.self, forCellReuseIdentifier: "MaterialTableViewCell")
tableView.dataSource = self
tableView.delegate = self
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView)
}
}
/// TableViewDataSource methods.
extension MessagesViewController: UITableViewDataSource {
/// Determines the number of rows in the tableView.
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count;
}
/// Returns the number of sections.
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
/// Prepares the cells within the tableView.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: MaterialTableViewCell = MaterialTableViewCell(style: .Subtitle, reuseIdentifier: "MaterialTableViewCell")
let item: Item = items[indexPath.row]
cell.selectionStyle = .None
cell.textLabel!.text = item.text
cell.textLabel!.font = RobotoFont.regular
cell.detailTextLabel!.text = item.detail
cell.detailTextLabel!.font = RobotoFont.regular
cell.detailTextLabel!.textColor = MaterialColor.grey.darken1
cell.imageView!.image = item.image?.resize(toWidth: 40)
cell.imageView!.layer.cornerRadius = 20
return cell
}
/// Prepares the header within the tableView.
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView(frame: CGRectMake(0, 0, view.bounds.width, 48))
header.backgroundColor = MaterialColor.white
let label: UILabel = UILabel()
label.font = RobotoFont.medium
label.textColor = MaterialColor.grey.darken1
label.text = "Today"
header.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(header, child: label, left: navigationController!.navigationBar.contentInset.left)
return header
}
}
/// UITableViewDelegate methods.
extension MessagesViewController: UITableViewDelegate {
/// Sets the tableView cell height.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
}
/// Sets the tableView header height.
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 48
}
}
......@@ -230,12 +230,12 @@ public extension UIView {
/// Grid reference.
public internal(set) var grid: Grid {
get {
return MaterialObjectAssociatedObject(self, key: &GridKey) {
return MaterialAssociatedObject(self, key: &GridKey) {
return Grid()
}
}
set(value) {
MaterialObjectAssociateObject(self, key: &GridKey, value: value)
MaterialAssociateObject(self, key: &GridKey, value: value)
}
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ Gets the Obj-C reference for the Grid object within the UIView extension.
- Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object.
*/
public func MaterialObjectAssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
public func MaterialAssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T {
return v
}
......@@ -52,6 +52,6 @@ Sets the Obj-C reference for the Grid object within the UIView extension.
- Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object.
*/
public func MaterialObjectAssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
public func MaterialAssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
}
\ No newline at end of file
......@@ -373,10 +373,54 @@ public class NavigationBar : UINavigationBar {
public override func layoutSubviews() {
super.layoutSubviews()
if nil != backItem && nil != topItem {
backButton.setImage(backButtonImage, forState: .Normal)
backButton.setImage(backButtonImage, forState: .Highlighted)
leftControls = [backButton]
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)
}
}
if nil == topItem?.titleView {
topItem?.titleView = MaterialView()
topItem?.titleView?.backgroundColor = nil
}
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)
}
}
topItem?.titleView?.grid.columns = columns
// rightControls?.first?.grid.offset.columns = columns
grid.reloadLayout()
}
}
}
......@@ -394,7 +438,7 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil
backgroundColor = MaterialColor.white
depth = .Depth1
contentInsetPreset = .WideRectangle3
contentInsetPreset = .None
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
setTitleVerticalPositionAdjustment(1, forBarMetrics: .Default)
setTitleVerticalPositionAdjustment(2, forBarMetrics: .Compact)
......@@ -429,44 +473,11 @@ public class NavigationBar : UINavigationBar {
private var NavigationBarKey: UInt8 = 0
public class NavigationBarControls {
/// A preset for contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A UIEdgeInsets for contentInset.
public var contentInset: UIEdgeInsets = MaterialEdgeInsetToValue(.None)
/// Preset for spacing value.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// Space between buttons.
public var spacing: CGFloat = 0
/// Inset for spacer button.
public var inset: CGFloat {
return MaterialDevice.landscape ? -28 : -20
}
public private(set) var backButton: MaterialButton
/// Left controls.
public var leftControls: Array<UIControl>?
/// Right controls.
public var rightControls: Array<UIControl>?
public init() {
backButton = FlatButton()
backButton.pulseScale = false
backButton.pulseColor = MaterialColor.white
}
}
public extension UINavigationBar {
......@@ -483,60 +494,55 @@ public extension UINavigationBar {
/// NavigationBarControls reference.
public internal(set) var controls: NavigationBarControls {
get {
return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) {
return MaterialAssociatedObject(self, key: &NavigationBarKey) {
return NavigationBarControls()
}
}
set(value) {
MaterialObjectAssociateObject(self, key: &NavigationBarKey, value: value)
MaterialAssociateObject(self, key: &NavigationBarKey, value: value)
}
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return controls.contentInsetPreset
return grid.contentInsetPreset
}
set(value) {
controls.contentInsetPreset = value
grid.contentInsetPreset = value
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
get {
return controls.contentInset
return grid.contentInset
}
set(value) {
controls.contentInset = value
grid.contentInset = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing {
get {
return controls.spacingPreset
return grid.spacingPreset
}
set(value) {
controls.spacingPreset = value
grid.spacingPreset = value
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return controls.spacing
return grid.spacing
}
set(value) {
controls.spacing = value
grid.spacing = value
}
}
/// Back button.
public var backButton: MaterialButton {
return controls.backButton
}
/// Left side UIControls.
public var leftControls: Array<UIControl>? {
get {
......@@ -546,18 +552,10 @@ public extension UINavigationBar {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48 - spacing, 44 - contentInset.top - contentInset.bottom)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = controls.inset + contentInset.left
c.append(spacer)
controls.leftControls = value
topItem?.leftBarButtonItems = c.reverse()
}
......@@ -572,18 +570,10 @@ public extension UINavigationBar {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
q.frame.size = CGSizeMake(48 - spacing, 44 - contentInset.top - contentInset.bottom)
if let p: UIButton = q as? UIButton {
p.contentEdgeInsets = UIEdgeInsetsZero
}
c.append(UIBarButtonItem(customView: q))
}
}
let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
spacer.width = controls.inset + contentInset.right
c.append(spacer)
controls.rightControls = value
topItem?.rightBarButtonItems = c.reverse()
}
......
......@@ -30,7 +30,7 @@
import UIKit
public class NavigationController : UINavigationController {
public class NavigationController : UINavigationController, UINavigationBarDelegate {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
......@@ -48,15 +48,6 @@ public class NavigationController : UINavigationController {
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
interactivePopGestureRecognizer?.delegate = nil
if let v: NavigationBar = navigationBar as? NavigationBar {
v.layoutSubviews()
v.backButton.removeTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
v.backButton.addTarget(self, action: "handleBackButton", forControlEvents: .TouchUpInside)
}
}
/// Handles the backButton.
internal func handleBackButton() {
popViewControllerAnimated(true)
navigationBar.layoutSubviews()
}
}
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