Commit a8137ed7 by Daniel Dahan

updated SideNavigationViewController programmatic example

parent 3455a52c
......@@ -242,7 +242,7 @@ class ViewController: UIViewController {
/// Prepares a text alignment example.
private func prepareAlignTitleAndDetailLabelToLeftExample() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.indigo.darken1
navigationBarView.backgroundColor = MaterialColor.blue.base
/*
To lighten the status bar - add the
......
......@@ -13,6 +13,8 @@
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA301C1B906600022BC6 /* BMainViewController.swift */; };
9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* SideViewController.swift */; };
96607E031C441F54008D47D8 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96607E021C441F54008D47D8 /* MaterialKit.framework */; };
96607E041C441F54008D47D8 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96607E021C441F54008D47D8 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -22,6 +24,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
96607E041C441F54008D47D8 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -37,6 +40,7 @@
9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9642FA301C1B906600022BC6 /* BMainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMainViewController.swift; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* SideViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideViewController.swift; sourceTree = "<group>"; };
96607E021C441F54008D47D8 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-gdulktuccbcfwbdfadtpxkworhyc/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -44,6 +48,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96607E031C441F54008D47D8 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -53,6 +58,7 @@
9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup;
children = (
96607E021C441F54008D47D8 /* MaterialKit.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */,
);
......
......@@ -12,7 +12,7 @@
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of MaterialKit nor the names of its
* * Neither the name of GraphKit nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
......@@ -28,61 +28,203 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import UIKit
import MaterialKit
private struct Item {
var text: String
var detail: String
var image: UIImage?
}
class AMainViewController: UIViewController {
lazy var enabledButton: RaisedButton = RaisedButton()
/// 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()
prepareSwapSideNavigationViewControllerExample()
prepareItems()
prepareTableView()
prepareNavigationBarView()
prepareMaterialKitButton()
}
internal func handleSwapViewControllers() {
sideNavigationViewController?.transitionFromMainViewController(BMainViewController(),
duration: 0.25,
options: .TransitionCrossDissolve,
animations: nil,
completion: nil)
/**
Handles the menu button click, which opens the
SideNavigationViewController.
*/
func handleMenuButton() {
sideNavigationViewController?.open()
}
internal func handleEnabledButton() {
if true == sideNavigationViewController?.enabled {
sideNavigationViewController?.enabled = false
enabledButton.setTitle("Disabled", forState: .Normal)
} else {
sideNavigationViewController?.enabled = true
enabledButton.setTitle("Enabled", forState: .Normal)
}
/// Prepares view.
private func prepareView() {
view.backgroundColor = MaterialColor.white
}
private func prepareView() {
view.backgroundColor = MaterialColor.blue.base
prepareEnabledButton()
/// 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")))
}
private func prepareEnabledButton() {
enabledButton.setTitle("Enabled", forState: .Normal)
enabledButton.addTarget(self, action: "handleEnabledButton", forControlEvents: .TouchUpInside)
/// Prepares the tableView.
private func prepareTableView() {
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self
tableView.delegate = self
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView, top: 70)
}
/// Prepares the navigationBarView.
private func prepareNavigationBarView() {
let navigationBarView: NavigationBarView = NavigationBarView()
navigationBarView.backgroundColor = MaterialColor.blue.base
/*
To lighten the status bar - add the
"View controller-based status bar appearance = NO"
to your info.plist file and set the following property.
*/
navigationBarView.statusBarStyle = .LightContent
// Title label.
let titleLabel: UILabel = UILabel()
titleLabel.text = "Inbox"
titleLabel.textAlignment = .Left
titleLabel.textColor = MaterialColor.white
titleLabel.font = RobotoFont.regularWithSize(20)
navigationBarView.titleLabel = titleLabel
navigationBarView.titleLabelInset.left = 64
// Detail label.
let detailLabel: UILabel = UILabel()
detailLabel.text = "Count: \(items.count)"
detailLabel.textAlignment = .Left
detailLabel.textColor = MaterialColor.white
detailLabel.font = RobotoFont.regularWithSize(12)
navigationBarView.detailLabel = detailLabel
navigationBarView.detailLabelInset.left = 64
// Menu button.
let img1: UIImage? = UIImage(named: "ic_menu_white")
let menuButton: FlatButton = FlatButton()
menuButton.pulseColor = MaterialColor.white
menuButton.pulseFill = true
menuButton.pulseScale = false
menuButton.setImage(img1, forState: .Normal)
menuButton.setImage(img1, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
// Add menuButton to left side.
navigationBarView.leftButtons = [menuButton]
// Search button.
let img2: UIImage? = UIImage(named: "ic_search_white")
let searchButton: FlatButton = FlatButton()
searchButton.pulseColor = MaterialColor.white
searchButton.pulseFill = true
searchButton.pulseScale = false
searchButton.setImage(img2, forState: .Normal)
searchButton.setImage(img2, forState: .Highlighted)
// Add searchButton to right side.
navigationBarView.rightButtons = [searchButton]
// Add the enabledButton through MaterialLayout.
view.addSubview(enabledButton)
enabledButton.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopRight(view, child: enabledButton, top: 124, right: 24)
MaterialLayout.size(view, child: enabledButton, width: 200, height: 50)
// To support orientation changes, use MaterialLayout.
view.addSubview(navigationBarView)
navigationBarView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: navigationBarView)
MaterialLayout.alignToParentHorizontally(view, child: navigationBarView)
MaterialLayout.height(view, child: navigationBarView, height: 70)
}
private func prepareSwapSideNavigationViewControllerExample() {
/// Prepares the MaterialKit button.
func prepareMaterialKitButton() {
let image: UIImage? = UIImage(named: "ic_materialkit_white")
let button: FabButton = FabButton()
button.addTarget(self, action: "handleSwapViewControllers", forControlEvents: .TouchUpInside)
button.setImage(image, forState: .Normal)
button.setImage(image, forState: .Highlighted)
// Add the button through MaterialLayout.
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottomRight(view, child: button, bottom: 24, right: 24)
MaterialLayout.size(view, child: button, width: 64, height: 64)
MaterialLayout.alignFromBottomRight(view, child: button, bottom: 16, right: 16)
MaterialLayout.size(view, child: button, width: 56, height: 56)
}
}
/// TableViewDataSource methods.
extension AMainViewController: 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: UITableViewCell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
let item: Item = items[indexPath.row]
cell.selectionStyle = .None
cell.textLabel!.text = item.text
cell.detailTextLabel!.text = item.detail
cell.detailTextLabel!.textColor = MaterialColor.grey.darken4
cell.imageView!.image = item.image?.resize(toWidth: 36)
cell.imageView!.layer.cornerRadius = 18
return cell
}
/// Prepares the header within the tableView.
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = MaterialColor.white
let label: UILabel = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = RobotoFont.mediumWithSize(16)
label.textColor = MaterialColor.grey.base
label.text = "Today"
view.addSubview(label)
MaterialLayout.alignToParent(view, child: label, left: 16)
return view
}
}
/// UITableViewDelegate methods.
extension AMainViewController: 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
}
}
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile1.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile2.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile3.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile4.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile5.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile6.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile7.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "Profile8.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_book.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_book_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_book_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_materialkit_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_materialkit_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_materialkit_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_menu_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_menu_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_search_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_search_white_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_settings.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_settings_2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_settings_3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -32,43 +32,52 @@ import UIKit
import MaterialKit
class BMainViewController: UIViewController {
lazy var enabledButton: RaisedButton = RaisedButton()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
// Examples of using SideNavigationViewController.
prepareSwapSideNavigationViewControllerExample()
prepareFabButton()
}
internal func handleSwapViewControllers() {
sideNavigationViewController?.transitionFromMainViewController(AMainViewController(),
duration: 0.25,
options: .TransitionCrossDissolve,
animations: nil,
completion: nil)
sideNavigationViewController?.open()
}
internal func handleEnabledButton() {
if true == sideNavigationViewController?.enabled {
sideNavigationViewController?.enabled = false
enabledButton.setTitle("Disabled", forState: .Normal)
} else {
sideNavigationViewController?.enabled = true
enabledButton.setTitle("Enabled", forState: .Normal)
}
}
/**
:name: prepareView
:description: General preparation statements.
*/
private func prepareView() {
view.backgroundColor = MaterialColor.green.base
view.backgroundColor = MaterialColor.blue.base
prepareEnabledButton()
}
private func prepareEnabledButton() {
enabledButton.setTitle(true == sideNavigationViewController?.enabled ? "Enabled" : "Disabled", forState: .Normal)
enabledButton.addTarget(self, action: "handleEnabledButton", forControlEvents: .TouchUpInside)
// Add the enabledButton through MaterialLayout.
view.addSubview(enabledButton)
enabledButton.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopRight(view, child: enabledButton, top: 124, right: 24)
MaterialLayout.size(view, child: enabledButton, width: 200, height: 50)
}
/**
:name: prepareGeneralSideNavigationViewControllerExample
:description: General usage example.
*/
private func prepareSwapSideNavigationViewControllerExample() {
private func prepareFabButton() {
let button: FabButton = FabButton()
button.backgroundColor = MaterialColor.yellow.base
button.addTarget(self, action: "handleSwapViewControllers", forControlEvents: .TouchUpInside)
// Add the button through MaterialLayout.
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromBottomLeft(view, child: button, bottom: 24, left: 24)
MaterialLayout.alignFromBottomRight(view, child: button, bottom: 24, right: 24)
MaterialLayout.size(view, child: button, width: 64, height: 64)
}
}
......
......@@ -31,16 +31,73 @@
import UIKit
import MaterialKit
class SideViewController: UIViewController, SideNavigationViewControllerDelegate {
private struct Item {
var text: String
var image: UIImage?
}
class SideViewController: UIViewController {
/// A tableView used to display navigation items.
private let tableView: UITableView = UITableView()
/// A list of all the navigation items.
private var items: Array<Item> = Array<Item>()
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareItems()
prepareTableView()
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.purple.base
}
/// Prepares the items that are displayed within the tableView.
private func prepareItems() {
items.append(Item(text: "Settings", image: UIImage(named: "ic_settings")))
}
/// Prepares the tableView.
private func prepareTableView() {
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .None
// Examples of using SideNavigationViewController.
prepareSwapSideNavigationViewControllerExample()
// Use MaterialLayout to easily align the tableView.
view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignToParent(view, child: tableView, top: 140)
}
}
/// TableViewDataSource methods.
extension SideViewController: UITableViewDataSource {
/// Determines the number of rows in the tableView.
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count;
}
internal func handleSwapViewControllers() {
/// Prepares the cells within the tableView.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
let item: Item = items[indexPath.row]
cell.selectionStyle = .None
cell.textLabel!.text = item.text
cell.imageView!.image = item.image
return cell
}
}
/// UITableViewDelegate methods.
extension SideViewController: UITableViewDelegate {
/// A delegation method that is executed when an item row is selected.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
sideNavigationViewController?.transitionFromMainViewController(sideNavigationViewController?.mainViewController is AMainViewController ? BMainViewController() : AMainViewController(),
duration: 0.25,
options: .TransitionCrossDissolve,
......@@ -50,29 +107,5 @@ class SideViewController: UIViewController, SideNavigationViewControllerDelegate
}
)
}
/**
:name: prepareView
:description: General preparation statements.
*/
private func prepareView() {
view.backgroundColor = MaterialColor.purple.base
}
/**
:name: prepareGeneralSideNavigationViewControllerExample
:description: General usage example.
*/
private func prepareSwapSideNavigationViewControllerExample() {
let button: FabButton = FabButton()
button.backgroundColor = MaterialColor.orange.base
button.addTarget(self, action: "handleSwapViewControllers", forControlEvents: .TouchUpInside)
// Add the button through MaterialLayout.
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTopRight(view, child: button, top: 24, right: 24)
MaterialLayout.size(view, child: button, width: 48, height: 48)
}
}
......@@ -81,7 +81,6 @@ The MaterialKit framework is a fast growing project and will encounter changes t
* [ImageCardView](#imagecardview)
* [CaptureView](#captureview)
* [MaterialColor](#materialcolor)
* [MaterialLayout](#materiallayout)
### Upcoming
......@@ -316,7 +315,7 @@ MaterialLayout.height(view, child: navigationBarView, height: 70)
<a name="sidenavigationviewcontroller"></a>
### SideNavigationViewController
As elegant as is effective, the SideNavigationViewController is an excellent way to organize your app. In the Examples directory, there is an example project using this wonderful component.
The SideNavigationViewController is an app wide navigation pattern. It generally provides overall app navigation with other useful items. Below is an example of the SideNavigationViewController and in the Examples Programmatic directory, an example project is available using this component.
![MaterialKitSideNavigationViewController](http://www.materialkit.io/MK/MaterialKitSideNavigationViewController.gif)
......
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