Commit 42e249cb by Daniel Dahan

updated example for BottomNavigationBar

parent 69dcb689
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_music_note_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_music_note_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_music_note_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -41,11 +41,6 @@ class ViewController: UIViewController {
prepareBottomNavigationBar()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
bottomNavigationBar.frame = CGRectMake(0, view.bounds.height - 56, view.bounds.width, 56)
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.white
......@@ -56,5 +51,21 @@ class ViewController: UIViewController {
bottomNavigationBar = BottomNavigationBar()
bottomNavigationBar.backgroundColor = MaterialColor.teal.base
view.addSubview(bottomNavigationBar)
let item1: BottomNavigationBarItem = BottomNavigationBarItem(title: "Music", image: UIImage(named:"ic_music_note_white")?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: UIImage(named:"ic_music_note_white"))
item1.setTitleColor(MaterialColor.white, forState: .Normal)
item1.setTitleColor(MaterialColor.white, forState: .Selected)
let item2: BottomNavigationBarItem = BottomNavigationBarItem(title: "Music", image: UIImage(named:"ic_music_note_white")?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: UIImage(named:"ic_music_note_white"))
item2.setTitleColor(MaterialColor.white, forState: .Normal)
item2.setTitleColor(MaterialColor.white, forState: .Selected)
let item3: BottomNavigationBarItem = BottomNavigationBarItem(title: "Music", image: UIImage(named:"ic_music_note_white"), selectedImage: UIImage(named:"ic_music_note_white"))
item3.setTitleColor(MaterialColor.blue.lighten3, forState: .Normal)
item3.setTitleColor(MaterialColor.white, forState: .Selected)
bottomNavigationBar.setItems([item1, item2, item3], animated: true)
// bottomNavigationBar.tintColor = MaterialColor.white
}
}
......@@ -73,6 +73,8 @@
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; };
96A71FB31C764E3200C0C4AE /* StatusBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71FB21C764E3200C0C4AE /* StatusBarView.swift */; };
96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71FB01C7649F800C0C4AE /* ControlView.swift */; };
96BAECE81CA3B4620048037C /* BottomNavigationBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BAECE71CA3B4620048037C /* BottomNavigationBarItem.swift */; };
96BAECEA1CA3B8B90048037C /* BottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BAECE91CA3B8B90048037C /* BottomNavigationController.swift */; };
96BE340F1C8E68EF007D02BE /* MaterialIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BE340E1C8E68EF007D02BE /* MaterialIcon.swift */; };
96CC08311C7CCB7C0034FF84 /* MaterialBorder.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC08321C7CCB7C0034FF84 /* MenuViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9626C2DD1C795017007CA8E0 /* MenuViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -205,6 +207,8 @@
96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; };
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
96BAECE71CA3B4620048037C /* BottomNavigationBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationBarItem.swift; sourceTree = "<group>"; };
96BAECE91CA3B8B90048037C /* BottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationController.swift; sourceTree = "<group>"; };
96BE340E1C8E68EF007D02BE /* MaterialIcon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialIcon.swift; sourceTree = "<group>"; };
96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarViewController.swift; sourceTree = "<group>"; };
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialCollectionView.swift; sourceTree = "<group>"; };
......@@ -358,6 +362,8 @@
isa = PBXGroup;
children = (
96A536641CA3A2C80069B3CC /* BottomNavigationBar.swift */,
96BAECE71CA3B4620048037C /* BottomNavigationBarItem.swift */,
96BAECE91CA3B8B90048037C /* BottomNavigationController.swift */,
);
name = BottomNavigation;
sourceTree = "<group>";
......@@ -786,7 +792,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96BAECEA1CA3B8B90048037C /* BottomNavigationController.swift in Sources */,
968F16F61C9260EC008CA3F6 /* Toolbar.swift in Sources */,
96BAECE81CA3B4620048037C /* BottomNavigationBarItem.swift in Sources */,
96D88C3D1C1328D800B91418 /* MaterialView.swift in Sources */,
960B23481C38480E00E96216 /* TextView.swift in Sources */,
96D88C291C1328D800B91418 /* MaterialBasicAnimation.swift in Sources */,
......
......@@ -32,12 +32,6 @@ import UIKit
@IBDesignable
public class BottomNavigationBar : UITabBar {
/// Left spacer moves the items to the left edge of the NavigationBar.
private var leftSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
/// Right spacer moves the items to the right edge of the NavigationBar.
private var rightSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
/// A preset for contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
......@@ -229,7 +223,18 @@ public class BottomNavigationBar : UITabBar {
public override func layoutSubviews() {
super.layoutSubviews()
if let v: Array<UITabBarItem> = items {
for item in v {
if nil == item.title {
item.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0)
} else {
item.titlePositionAdjustment.vertical = -8
}
}
}
if let v: UIView = superview {
frame = CGRectMake(0, v.bounds.height - 56, v.bounds.width, 56)
}
}
/**
......
/*
* 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
@IBDesignable
public class BottomNavigationBarItem : UITabBarItem {
/// Sets the color of the title color for a state.
public func setTitleColor(color: UIColor?, forState: UIControlState) {
setTitleTextAttributes([NSForegroundColorAttributeName: MaterialColor.white], forState: .Normal)
}
}
/*
* 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
@IBDesignable
public class BottomNavigationController : UITabBarController {
}
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