Commit 3f8dc4cc by Daniel Dahan

working NavigationController

parent 7bfafdfa
......@@ -52,7 +52,24 @@ class FeedViewController: UIViewController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationBarViewController?.navigationBarView.titleLabel?.text = "Feed"
navigationController?.navigationBar.statusBarStyle = .LightContent
navigationController?.navigationBar.backgroundColor = MaterialColor.blue.base
let image = UIImage(named: "ic_menu_white")
// Menu button.
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = MaterialColor.white
menuButton.pulseScale = false
menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
navigationController?.navigationBar.rightControls = [menuButton]
}
internal func handleMenuButton() {
print("handled")
}
/// Prepares view.
......@@ -184,6 +201,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
let image: UIImage? = UIImage(named: "ic_share_white_18pt")?.imageWithRenderingMode(.AlwaysTemplate)
let shareButton: FlatButton = FlatButton()
shareButton.pulseScale = false
shareButton.pulseColor = MaterialColor.grey.base
shareButton.tintColor = MaterialColor.grey.base
shareButton.setImage(image, forState: .Normal)
......
......@@ -43,9 +43,6 @@ class ViewController: UIViewController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.backgroundColor = MaterialColor.blue.base
}
/// Prepares view.
......
......@@ -33,6 +33,8 @@
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
96334EF81C8B84880083986B /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96334EF71C8B84880083986B /* NavigationBar.swift */; };
96334EFA1C8B849A0083986B /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96334EF91C8B849A0083986B /* NavigationController.swift */; };
96334F011C8B8BD30083986B /* Material+UIImage+Blank.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96334F001C8B8BD30083986B /* Material+UIImage+Blank.swift */; };
96334F031C8BA14C0083986B /* Material+Obj-C.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96334F021C8BA14C0083986B /* Material+Obj-C.swift */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
96442ADB1C28EEFA00C3C574 /* TextField.swift in Headers */ = {isa = PBXBuildFile; fileRef = 966F57B71C226D75009185B7 /* TextField.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96442ADD1C28EF3700C3C574 /* MaterialTableViewCell.swift */; };
......@@ -172,6 +174,8 @@
96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96334EF71C8B84880083986B /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = "<group>"; };
96334EF91C8B849A0083986B /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; };
96334F001C8B8BD30083986B /* Material+UIImage+Blank.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIImage+Blank.swift"; sourceTree = "<group>"; };
96334F021C8BA14C0083986B /* Material+Obj-C.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+Obj-C.swift"; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
963832591B88E31A0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
......@@ -498,6 +502,7 @@
96D88C501C132A2C00B91418 /* Extensions */ = {
isa = PBXGroup;
children = (
96334F021C8BA14C0083986B /* Material+Obj-C.swift */,
96D88BFE1C1328D800B91418 /* Material+UIFont.swift */,
960B23261C383E5500E96216 /* Material+String.swift */,
960B23281C383EAA00E96216 /* Material+UIImage.swift */,
......@@ -507,6 +512,7 @@
960B232C1C383EAA00E96216 /* Material+UIImage+Resize.swift */,
960B232D1C383EAA00E96216 /* Material+UIImage+Size.swift */,
96DBA7351C61198400844821 /* Material+UIImage+Color.swift */,
96334F001C8B8BD30083986B /* Material+UIImage+Blank.swift */,
);
name = Extensions;
sourceTree = "<group>";
......@@ -774,7 +780,9 @@
96D88C331C1328D800B91418 /* MaterialLabel.swift in Sources */,
96D88C281C1328D800B91418 /* MaterialAnimation.swift in Sources */,
96A71F301C72E41100C0C4AE /* NavigationBarViewController.swift in Sources */,
96334F011C8B8BD30083986B /* Material+UIImage+Blank.swift in Sources */,
960B232E1C383EAA00E96216 /* Material+UIImage.swift in Sources */,
96334F031C8BA14C0083986B /* Material+Obj-C.swift in Sources */,
96D88C451C1328D800B91418 /* RobotoFont.swift in Sources */,
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */,
96D88C2C1C1328D800B91418 /* MaterialColor.swift in Sources */,
......
......@@ -222,48 +222,20 @@ public class Grid {
}
}
/**
Gets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object.
*/
private func GridAssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T {
return v
}
let v: T = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v
}
/**
Sets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object.
*/
private func GridAssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
}
/// A memory reference to the Grid instance for UIView extensions.
private var gridKey: UInt8 = 0
private var GridKey: UInt8 = 0
/// Grid extension for UIView.
public extension UIView {
/// Grid reference.
public var grid: Grid {
get {
return GridAssociatedObject(self, key: &gridKey) {
return MaterialObjectAssociatedObject(self, key: &GridKey) {
return Grid()
}
}
set(value) {
GridAssociateObject(self, key: &gridKey, value: value)
MaterialObjectAssociateObject(self, key: &GridKey, value: value)
}
}
}
\ No newline at end of file
/*
* 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.
*/
/**
Gets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- 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 {
if let v: T = objc_getAssociatedObject(base, key) as? T {
return v
}
let v: T = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v
}
/**
Sets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- 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) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
}
\ No newline at end of file
/*
* 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
public extension UIImage {
/**
Creates an clear image.
- Returns: A UIImage that is clear.
*/
public class func clearImage() -> UIImage {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36, 36), false, 0)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
......@@ -31,6 +31,12 @@
import UIKit
public extension UIImage {
/**
Creates an Image that is a color.
- Parameter color: The UIColor to create the image from.
- Parameter size: The size of the image to create.
- Returns: A UIImage that is the color passed in.
*/
public class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect = CGRectMake(0, 0, size.width, size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
......
......@@ -30,8 +30,93 @@
import UIKit
public class NavigationBar : UINavigationBar {
/// A memory reference to the Grid instance for UIView extensions.
private var NavigationBarKey: UInt8 = 0
public class Controls {
/// Left controls.
public var leftControls: Array<UIControl>?
/// Right controls.
public var rightControls: Array<UIControl>?
}
public extension UINavigationBar {
/// Grid reference.
public var controls: Controls {
get {
return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) {
return Controls()
}
}
set(value) {
MaterialObjectAssociateObject(self, key: &NavigationBarKey, value: value)
}
}
public var title: String? {
get {
return topItem?.title
}
set(value) {
topItem?.title = value
}
}
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle {
get {
return UIApplication.sharedApplication().statusBarStyle
}
set(value) {
UIApplication.sharedApplication().statusBarStyle = value
}
}
public var leftControls: Array<UIControl>? {
get {
return controls.leftControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
let b: UIBarButtonItem = UIBarButtonItem(customView: q)
b.width = q.intrinsicContentSize().width
c.append(b)
}
}
controls.leftControls = value
topItem?.leftBarButtonItems = c
}
}
public var rightControls: Array<UIControl>? {
get {
return controls.rightControls
}
set(value) {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value {
for q in v {
let b: UIBarButtonItem = UIBarButtonItem(customView: q)
b.width = q.intrinsicContentSize().width
c.append(b)
}
}
controls.rightControls = value
topItem?.rightBarButtonItems = c
}
}
}
public class NavigationBar : UINavigationBar {
/**
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
*/
public var backButtonImage: UIImage? {
didSet {
if nil == backButtonImage {
......@@ -49,6 +134,79 @@ public class NavigationBar : UINavigationBar {
}
}
/// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.CGColor
}
}
/// A property that accesses the backing layer's shadowOffset.
public var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set(value) {
layer.shadowOffset = value
}
}
/// A property that accesses the backing layer's shadowOpacity.
public var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set(value) {
layer.shadowOpacity = value
}
}
/// A property that accesses the backing layer's shadowRadius.
public var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set(value) {
layer.shadowRadius = value
}
}
/// A property that accesses the backing layer's shadowPath.
public var shadowPath: CGPath? {
get {
return layer.shadowPath
}
set(value) {
layer.shadowPath = value
}
}
/// Enables automatic shadowPath sizing.
public var shadowPathAutoSizeEnabled: Bool = false {
didSet {
if shadowPathAutoSizeEnabled {
// layoutShadowPath()
} else {
shadowPath = nil
}
}
}
/**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depth: MaterialDepth = .None {
didSet {
let value: MaterialDepthType = MaterialDepthToValue(depth)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
// layoutShadowPath()
}
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
prepareView()
......@@ -60,6 +218,10 @@ public class NavigationBar : UINavigationBar {
}
public func prepareView() {
translucent = false
barStyle = .Black
backButtonImage = nil
backgroundColor = MaterialColor.white
depth = .Depth1
}
}
......@@ -48,7 +48,12 @@ public class NavigationController : UINavigationController {
prepareView()
}
public override func viewDidLoad() {
super.viewDidLoad()
prepareView()
}
public func prepareView() {
navigationItem.title = "Title"
}
}
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