Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
7d7e0975
Commit
7d7e0975
authored
Mar 06, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working NavigationController -> NavigationBar Back Button
parent
0ff4ab03
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
283 additions
and
264 deletions
+283
-264
Examples/Programmatic/App/App.xcodeproj/project.pbxproj
+0
-4
Examples/Programmatic/App/App/AppDelegate.swift
+1
-1
Examples/Programmatic/App/App/FeedViewController.swift
+12
-8
Examples/Programmatic/App/App/InboxViewController.swift
+5
-2
Examples/Programmatic/App/App/Info.plist
+4
-2
Examples/Programmatic/App/App/ViewController.swift
+0
-58
Sources/Grid.swift
+1
-1
Sources/MaterialEdgeInset.swift
+28
-30
Sources/NavigationBar.swift
+214
-144
Sources/NavigationController.swift
+10
-8
Sources/SideNavigationViewController.swift
+8
-6
No files found.
Examples/Programmatic/App/App.xcodeproj/project.pbxproj
View file @
7d7e0975
...
...
@@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
96334EFC1C8B85F40083986B
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96334EFB1C8B85F40083986B
/* Material.framework */
;
};
96334EFD1C8B85F40083986B
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96334EFB1C8B85F40083986B
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
96334EFF1C8B876E0083986B
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96334EFE1C8B876E0083986B
/* ViewController.swift */
;
};
9663F9321C7A744600AF0965
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9311C7A744600AF0965
/* AppDelegate.swift */
;
};
9663F9341C7A744600AF0965
/* SearchListViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9331C7A744600AF0965
/* SearchListViewController.swift */
;
};
9663F9391C7A744600AF0965
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9381C7A744600AF0965
/* Assets.xcassets */
;
};
...
...
@@ -39,7 +38,6 @@
/* Begin PBXFileReference section */
96334EFB1C8B85F40083986B
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
96334EFE1C8B876E0083986B
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
9663F92E1C7A744600AF0965
/* App.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
App.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
9663F9311C7A744600AF0965
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
9663F9331C7A744600AF0965
/* SearchListViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
SearchListViewController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -99,7 +97,6 @@
9663F9381C7A744600AF0965
/* Assets.xcassets */
,
9663F93A1C7A744600AF0965
/* LaunchScreen.storyboard */
,
9663F93D1C7A744600AF0965
/* Info.plist */
,
96334EFE1C8B876E0083986B
/* ViewController.swift */
,
);
path
=
App
;
sourceTree
=
"<group>"
;
...
...
@@ -175,7 +172,6 @@
isa
=
PBXSourcesBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
96334EFF1C8B876E0083986B
/* ViewController.swift in Sources */
,
9663F94A1C7A74B500AF0965
/* AppSearchBarViewController.swift in Sources */
,
96CC08881C7FEBD60034FF84
/* InboxViewController.swift in Sources */
,
9663F9501C7A74FC00AF0965
/* AppRightViewController.swift in Sources */
,
...
...
Examples/Programmatic/App/App/AppDelegate.swift
View file @
7d7e0975
...
...
@@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.
window
=
UIWindow
(
frame
:
UIScreen
.
mainScreen
()
.
bounds
)
// window!.rootViewController = SideNavigationViewController(mainViewController: AppMenuViewController(mainViewController: AppNavigationBarViewController(mainViewController: InboxViewController())), leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
window
!.
rootViewController
=
NavigationController
(
rootViewController
:
Feed
ViewController
())
window
!.
rootViewController
=
SideNavigationViewController
(
mainViewController
:
NavigationController
(
rootViewController
:
FeedViewController
()),
leftViewController
:
AppLeft
ViewController
())
window
!.
makeKeyAndVisible
()
return
true
}
...
...
Examples/Programmatic/App/App/FeedViewController.swift
View file @
7d7e0975
...
...
@@ -46,7 +46,6 @@ class FeedViewController: UIViewController {
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
collectionView
.
frame
=
view
.
bounds
collectionView
.
reloadData
()
}
...
...
@@ -59,11 +58,11 @@ class FeedViewController: UIViewController {
// Menu button.
let
menuButton
:
FlatButton
=
FlatButton
()
menuButton
.
pulseColor
=
MaterialColor
.
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)
menuButton
.
addTarget
(
self
,
action
:
"handleMenuButton"
,
forControlEvents
:
.
TouchUpInside
)
// Switch control.
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Small
)
...
...
@@ -71,18 +70,18 @@ class FeedViewController: UIViewController {
// Search button.
image
=
UIImage
(
named
:
"ic_search_white"
)
let
searchButton
:
FlatButton
=
FlatButton
()
searchButton
.
pulseColor
=
MaterialColor
.
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)
searchButton
.
addTarget
(
self
,
action
:
"handleSearchButton"
,
forControlEvents
:
.
TouchUpInside
)
navigationController
?
.
navigationBar
.
leftControls
=
[
menuButton
]
navigationController
?
.
navigationBar
.
rightControls
=
[
switchControl
,
searchButton
]
}
internal
func
handleMenuButton
()
{
print
(
"handled"
)
sideNavigationViewController
?
.
toggleLeftView
(
)
}
internal
func
handleSearchButton
()
{
...
...
@@ -94,7 +93,9 @@ class FeedViewController: UIViewController {
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
navigationController
?
.
navigationBar
.
tintColor
=
MaterialColor
.
white
navigationController
?
.
navigationBar
.
backgroundColor
=
MaterialColor
.
blue
.
base
navigationController
?
.
navigationBar
.
backButton
.
pulseColor
=
MaterialColor
.
white
}
/// Prepares the collectionView
...
...
@@ -102,11 +103,12 @@ class FeedViewController: UIViewController {
collectionView
.
dataSource
=
self
collectionView
.
delegate
=
self
collectionView
.
spacingPreset
=
.
Spacing1
collectionView
.
contentInsetPreset
=
.
Square1
collectionView
.
registerClass
(
MaterialCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
"MaterialCollectionViewCell"
)
// To avoid being hidden under the hovering MenuView.
view
.
addSubview
(
collectionView
)
collectionView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
view
,
child
:
collectionView
)
// collectionView.scrollDirection = .Horizontal // Uncomment to see the horizontal scroll direction.
}
...
...
@@ -204,6 +206,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
cardView
!.
pulseScale
=
false
cardView
!.
divider
=
false
cardView
!.
depth
=
.
None
cardView
!.
cornerRadiusPreset
=
.
None
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
textColor
=
MaterialColor
.
grey
.
darken4
...
...
@@ -246,6 +249,6 @@ extension FeedViewController: MaterialCollectionViewDelegate {
/// Executed when an item is selected.
func
collectionView
(
collectionView
:
UICollectionView
,
didSelectItemAtIndexPath
indexPath
:
NSIndexPath
)
{
// print(indexPath)
navigationController
?
.
pushViewController
(
ViewController
(),
animated
:
true
)
navigationController
?
.
pushViewController
(
Inbox
ViewController
(),
animated
:
true
)
}
}
\ No newline at end of file
Examples/Programmatic/App/App/InboxViewController.swift
View file @
7d7e0975
...
...
@@ -53,7 +53,10 @@ class InboxViewController: UIViewController {
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
navigationBarViewController
?
.
navigationBarView
.
titleLabel
?
.
text
=
"Inbox"
navigationItem
.
title
=
"Messages"
navigationController
?
.
navigationBar
.
topItem
?
.
title
=
""
navigationController
?
.
navigationBar
.
leftControls
=
[]
}
/**
...
...
@@ -135,7 +138,7 @@ extension InboxViewController: UITableViewDataSource {
header
.
addSubview
(
label
)
label
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignToParent
(
header
,
child
:
label
,
left
:
navigation
BarViewController
!.
navigationBarView
.
contentInset
.
left
+
navigationBarViewController
!.
navigationBarView
.
spacing
)
MaterialLayout
.
alignToParent
(
header
,
child
:
label
,
left
:
navigation
Controller
!.
navigationBar
.
contentInset
.
left
)
return
header
}
...
...
Examples/Programmatic/App/App/Info.plist
View file @
7d7e0975
...
...
@@ -2,8 +2,6 @@
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
CFBundleDevelopmentRegion
<
/k
e
y
>
<
string
>
en
<
/string
>
<
k
e
y
>
CFBundleExecutable
<
/k
e
y
>
...
...
@@ -30,6 +28,8 @@
<
a
rr
a
y
>
<
string
>
armv7
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIStatusBarHidden
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
...
...
@@ -44,5 +44,7 @@
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
/
d
i
c
t
>
<
/plist
>
Examples/Programmatic/App/App/ViewController.swift
deleted
100644 → 0
View file @
0ff4ab03
/*
* 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.
*/
/*
The following example shows how to dynamically size MaterialCollectionViewCells.
*/
import
UIKit
import
Material
class
ViewController
:
UIViewController
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
}
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
navigationItem
.
title
=
"Material"
navigationController
?
.
navigationBar
.
leftControls
=
[]
navigationController
?
.
navigationBar
.
rightControls
=
[]
}
/// Prepares view.
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
}
}
\ No newline at end of file
Sources/Grid.swift
View file @
7d7e0975
...
...
@@ -228,7 +228,7 @@ private var GridKey: UInt8 = 0
/// Grid extension for UIView.
public
extension
UIView
{
/// Grid reference.
public
var
grid
:
Grid
{
public
internal(set)
var
grid
:
Grid
{
get
{
return
MaterialObjectAssociatedObject
(
self
,
key
:
&
GridKey
)
{
return
Grid
()
...
...
Sources/MaterialEdgeInset.swift
View file @
7d7e0975
...
...
@@ -67,9 +67,7 @@ public enum MaterialEdgeInset {
case
TallRectangle9
}
/**
:name: MaterialEdgeInsetToValue
*/
/// Converts the MaterialEdgeInset to a UIEdgeInsets value.
public
func
MaterialEdgeInsetToValue
(
inset
:
MaterialEdgeInset
)
->
UIEdgeInsets
{
switch
inset
{
case
.
None
:
...
...
@@ -77,62 +75,62 @@ public func MaterialEdgeInsetToValue(inset: MaterialEdgeInset) -> UIEdgeInsets {
// square
case
.
Square1
:
return
UIEdgeInsets
(
top
:
4
,
left
:
4
,
bottom
:
4
,
right
:
4
)
return
UIEdgeInsets
Make
(
4
,
4
,
4
,
4
)
case
.
Square2
:
return
UIEdgeInsets
(
top
:
8
,
left
:
8
,
bottom
:
8
,
right
:
8
)
return
UIEdgeInsets
Make
(
8
,
8
,
8
,
8
)
case
.
Square3
:
return
UIEdgeInsets
(
top
:
16
,
left
:
16
,
bottom
:
16
,
right
:
16
)
return
UIEdgeInsets
Make
(
16
,
16
,
16
,
16
)
case
.
Square4
:
return
UIEdgeInsets
(
top
:
24
,
left
:
24
,
bottom
:
24
,
right
:
24
)
return
UIEdgeInsets
Make
(
24
,
24
,
24
,
24
)
case
.
Square5
:
return
UIEdgeInsets
(
top
:
32
,
left
:
32
,
bottom
:
32
,
right
:
32
)
return
UIEdgeInsets
Make
(
32
,
32
,
32
,
32
)
case
.
Square6
:
return
UIEdgeInsets
(
top
:
40
,
left
:
40
,
bottom
:
40
,
right
:
40
)
return
UIEdgeInsets
Make
(
40
,
40
,
40
,
40
)
case
.
Square7
:
return
UIEdgeInsets
(
top
:
48
,
left
:
48
,
bottom
:
48
,
right
:
48
)
return
UIEdgeInsets
Make
(
48
,
48
,
48
,
48
)
case
.
Square8
:
return
UIEdgeInsets
(
top
:
56
,
left
:
56
,
bottom
:
56
,
right
:
56
)
return
UIEdgeInsets
Make
(
56
,
56
,
56
,
56
)
case
.
Square9
:
return
UIEdgeInsets
(
top
:
64
,
left
:
64
,
bottom
:
64
,
right
:
64
)
return
UIEdgeInsets
Make
(
64
,
64
,
64
,
64
)
// rectangle
case
.
WideRectangle1
:
return
UIEdgeInsets
(
top
:
2
,
left
:
4
,
bottom
:
2
,
right
:
4
)
return
UIEdgeInsets
Make
(
2
,
4
,
2
,
4
)
case
.
WideRectangle2
:
return
UIEdgeInsets
(
top
:
4
,
left
:
8
,
bottom
:
4
,
right
:
8
)
return
UIEdgeInsets
Make
(
4
,
8
,
4
,
8
)
case
.
WideRectangle3
:
return
UIEdgeInsets
(
top
:
8
,
left
:
16
,
bottom
:
8
,
right
:
16
)
return
UIEdgeInsets
Make
(
8
,
16
,
8
,
16
)
case
.
WideRectangle4
:
return
UIEdgeInsets
(
top
:
12
,
left
:
24
,
bottom
:
12
,
right
:
24
)
return
UIEdgeInsets
Make
(
12
,
24
,
12
,
24
)
case
.
WideRectangle5
:
return
UIEdgeInsets
(
top
:
16
,
left
:
32
,
bottom
:
16
,
right
:
32
)
return
UIEdgeInsets
Make
(
16
,
32
,
16
,
32
)
case
.
WideRectangle6
:
return
UIEdgeInsets
(
top
:
20
,
left
:
40
,
bottom
:
20
,
right
:
40
)
return
UIEdgeInsets
Make
(
20
,
40
,
20
,
40
)
case
.
WideRectangle7
:
return
UIEdgeInsets
(
top
:
24
,
left
:
48
,
bottom
:
24
,
right
:
48
)
return
UIEdgeInsets
Make
(
24
,
48
,
24
,
48
)
case
.
WideRectangle8
:
return
UIEdgeInsets
(
top
:
28
,
left
:
56
,
bottom
:
28
,
right
:
56
)
return
UIEdgeInsets
Make
(
28
,
56
,
28
,
56
)
case
.
WideRectangle9
:
return
UIEdgeInsets
(
top
:
32
,
left
:
64
,
bottom
:
32
,
right
:
64
)
return
UIEdgeInsets
Make
(
32
,
64
,
32
,
64
)
// flipped rectangle
case
.
TallRectangle1
:
return
UIEdgeInsets
(
top
:
4
,
left
:
2
,
bottom
:
4
,
right
:
2
)
return
UIEdgeInsets
Make
(
4
,
2
,
4
,
2
)
case
.
TallRectangle2
:
return
UIEdgeInsets
(
top
:
8
,
left
:
4
,
bottom
:
8
,
right
:
4
)
return
UIEdgeInsets
Make
(
8
,
4
,
8
,
4
)
case
.
TallRectangle3
:
return
UIEdgeInsets
(
top
:
16
,
left
:
8
,
bottom
:
16
,
right
:
8
)
return
UIEdgeInsets
Make
(
16
,
8
,
16
,
8
)
case
.
TallRectangle4
:
return
UIEdgeInsets
(
top
:
24
,
left
:
12
,
bottom
:
24
,
right
:
12
)
return
UIEdgeInsets
Make
(
24
,
12
,
24
,
12
)
case
.
TallRectangle5
:
return
UIEdgeInsets
(
top
:
32
,
left
:
16
,
bottom
:
32
,
right
:
16
)
return
UIEdgeInsets
Make
(
32
,
16
,
32
,
16
)
case
.
TallRectangle6
:
return
UIEdgeInsets
(
top
:
40
,
left
:
20
,
bottom
:
40
,
right
:
20
)
return
UIEdgeInsets
Make
(
40
,
20
,
40
,
20
)
case
.
TallRectangle7
:
return
UIEdgeInsets
(
top
:
48
,
left
:
24
,
bottom
:
48
,
right
:
24
)
return
UIEdgeInsets
Make
(
48
,
24
,
48
,
24
)
case
.
TallRectangle8
:
return
UIEdgeInsets
(
top
:
56
,
left
:
28
,
bottom
:
56
,
right
:
28
)
return
UIEdgeInsets
Make
(
56
,
28
,
56
,
28
)
case
.
TallRectangle9
:
return
UIEdgeInsets
(
top
:
64
,
left
:
32
,
bottom
:
64
,
right
:
32
)
return
UIEdgeInsets
Make
(
64
,
32
,
64
,
32
)
}
}
Sources/NavigationBar.swift
View file @
7d7e0975
...
...
@@ -30,106 +30,6 @@
import
UIKit
/// A memory reference to the Grid instance for UIView extensions.
private
var
NavigationBarKey
:
UInt8
=
0
public
class
NavigationBarControls
{
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
didSet
{
contentInset
=
MaterialEdgeInsetToValue
(
contentInsetPreset
)
}
}
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
/// Left controls.
public
var
leftControls
:
Array
<
UIControl
>
?
/// Right controls.
public
var
rightControls
:
Array
<
UIControl
>
?
public
init
()
{
contentInsetPreset
=
.
Square2
contentInset
=
MaterialEdgeInsetToValue
(
.
Square2
)
}
}
public
extension
UINavigationBar
{
/// NavigationBarControls reference.
public
var
controls
:
NavigationBarControls
{
get
{
return
MaterialObjectAssociatedObject
(
self
,
key
:
&
NavigationBarKey
)
{
return
NavigationBarControls
()
}
}
set
(
value
)
{
MaterialObjectAssociateObject
(
self
,
key
:
&
NavigationBarKey
,
value
:
value
)
}
}
/// Device status bar style.
public
var
statusBarStyle
:
UIStatusBarStyle
{
get
{
return
MaterialDevice
.
statusBarStyle
}
set
(
value
)
{
MaterialDevice
.
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
{
q
.
frame
.
size
=
CGSizeMake
(
48
,
32
)
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
=
-
20
+
controls
.
contentInset
.
left
c
.
append
(
spacer
)
controls
.
leftControls
=
value
topItem
?
.
leftBarButtonItems
=
c
.
reverse
()
}
}
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
{
q
.
frame
.
size
=
CGSizeMake
(
48
,
32
)
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
=
-
20
+
controls
.
contentInset
.
right
c
.
append
(
spacer
)
controls
.
rightControls
=
value
topItem
?
.
rightBarButtonItems
=
c
.
reverse
()
}
}
}
public
class
NavigationBar
:
UINavigationBar
{
/**
A CAShapeLayer used to manage elements that would be affected by
...
...
@@ -224,43 +124,6 @@ public class NavigationBar : UINavigationBar {
}
}
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
return
grid
.
contentInsetPreset
}
set
(
value
)
{
grid
.
contentInsetPreset
=
value
}
}
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
{
get
{
return
grid
.
contentInset
}
set
(
value
)
{
grid
.
contentInset
=
value
}
}
/// A preset wrapper around spacing.
public
var
spacingPreset
:
MaterialSpacing
=
.
None
{
didSet
{
spacing
=
MaterialSpacingToValue
(
spacingPreset
)
}
}
/// A wrapper around grid.spacing.
public
var
spacing
:
CGFloat
{
get
{
return
grid
.
spacing
}
set
(
value
)
{
grid
.
spacing
=
value
}
}
/**
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
...
...
@@ -405,7 +268,6 @@ public class NavigationBar : UINavigationBar {
}
}
/// A property that sets the cornerRadius of the backing layer.
public
var
cornerRadiusPreset
:
MaterialRadius
=
.
None
{
didSet
{
...
...
@@ -473,29 +335,72 @@ public class NavigationBar : UINavigationBar {
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
contentsGravityPreset
=
.
ResizeAspectFill
super
.
init
(
coder
:
aDecoder
)
prepareView
()
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public
override
init
(
frame
:
CGRect
)
{
contentsGravityPreset
=
.
ResizeAspectFill
super
.
init
(
frame
:
frame
)
prepareView
()
}
/// A convenience initializer.
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
/// Overriding the layout callback for sublayers.
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
layoutVisualLayer
()
layoutShadowPath
()
}
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
leftControls
=
leftControls
rightControls
=
rightControls
if
nil
!=
backItem
&&
nil
!=
topItem
{
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Normal
)
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Highlighted
)
leftControls
=
[
backButton
]
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public
func
prepareView
()
{
translucent
=
false
prepareVisualLayer
()
barStyle
=
.
Black
translucent
=
false
backButtonImage
=
nil
backgroundColor
=
MaterialColor
.
white
depth
=
.
Depth1
spacingPreset
=
.
Spacing2
contentInsetPreset
=
.
Square2
contentInsetPreset
=
.
WideRectangle3
titleTextAttributes
=
[
NSFontAttributeName
:
RobotoFont
.
regularWithSize
(
20
)]
prepareVisualLayer
(
)
backgroundColor
=
MaterialColor
.
white
setTitleVerticalPositionAdjustment
(
1
,
forBarMetrics
:
.
Default
)
setTitleVerticalPositionAdjustment
(
2
,
forBarMetrics
:
.
Compact
)
}
/// Prepares the visualLayer property.
...
...
@@ -510,7 +415,7 @@ public class NavigationBar : UINavigationBar {
visualLayer
.
frame
=
bounds
visualLayer
.
cornerRadius
=
cornerRadius
}
/// Sets the shadow path.
internal
func
layoutShadowPath
()
{
if
shadowPathAutoSizeEnabled
{
...
...
@@ -522,3 +427,168 @@ public class NavigationBar : UINavigationBar {
}
}
}
/// A memory reference to the Grid instance for UIView extensions.
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
?
-
20
:
-
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
.
pulseColor
=
nil
backButton
.
pulseScale
=
false
}
}
public
extension
UINavigationBar
{
/// Device status bar style.
public
var
statusBarStyle
:
UIStatusBarStyle
{
get
{
return
MaterialDevice
.
statusBarStyle
}
set
(
value
)
{
MaterialDevice
.
statusBarStyle
=
value
}
}
/// NavigationBarControls reference.
public
internal(set)
var
controls
:
NavigationBarControls
{
get
{
return
MaterialObjectAssociatedObject
(
self
,
key
:
&
NavigationBarKey
)
{
return
NavigationBarControls
()
}
}
set
(
value
)
{
MaterialObjectAssociateObject
(
self
,
key
:
&
NavigationBarKey
,
value
:
value
)
}
}
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
{
get
{
return
controls
.
contentInsetPreset
}
set
(
value
)
{
controls
.
contentInsetPreset
=
value
}
}
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
{
get
{
return
controls
.
contentInset
}
set
(
value
)
{
controls
.
contentInset
=
value
}
}
/// A preset wrapper around spacing.
public
var
spacingPreset
:
MaterialSpacing
{
get
{
return
controls
.
spacingPreset
}
set
(
value
)
{
controls
.
spacingPreset
=
value
}
}
/// A wrapper around grid.spacing.
public
var
spacing
:
CGFloat
{
get
{
return
controls
.
spacing
}
set
(
value
)
{
controls
.
spacing
=
value
}
}
/// Back button.
public
var
backButton
:
MaterialButton
{
return
controls
.
backButton
}
/// Left side UIControls.
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
{
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
()
}
}
/// Right side UIControls.
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
{
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
()
}
}
}
Sources/NavigationController.swift
View file @
7d7e0975
...
...
@@ -34,26 +34,28 @@ public class NavigationController : UINavigationController {
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepareView
()
}
public
override
init
(
nibName
nibNameOrNil
:
String
?,
bundle
nibBundleOrNil
:
NSBundle
?)
{
super
.
init
(
nibName
:
nibNameOrNil
,
bundle
:
nibBundleOrNil
)
prepareView
()
}
public
override
init
(
rootViewController
:
UIViewController
)
{
super
.
init
(
navigationBarClass
:
NavigationBar
.
self
,
toolbarClass
:
nil
)
setViewControllers
([
rootViewController
],
animated
:
false
)
prepareView
()
}
public
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
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
)
}
}
public
func
prepareView
()
{
navigationItem
.
title
=
"Title"
/// Handles the backButton.
internal
func
handleBackButton
()
{
popViewControllerAnimated
(
true
)
}
}
Sources/SideNavigationViewController.swift
View file @
7d7e0975
...
...
@@ -843,12 +843,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
private
func
toggleStatusBar
(
hide
:
Bool
=
false
)
{
if
hideStatusBar
{
// General alignment.
if
.
iPhone
==
MaterialDevice
.
type
&&
MaterialDevice
.
landscape
{
UIApplication
.
sharedApplication
()
.
statusBarHidden
=
true
}
else
{
UIApplication
.
sharedApplication
()
.
statusBarHidden
=
opened
?
true
:
hide
}
UIView
.
animateWithDuration
(
0.25
,
animations
:
{
[
weak
self
]
in
// General alignment.
if
.
iPhone
==
MaterialDevice
.
type
&&
MaterialDevice
.
landscape
{
UIApplication
.
sharedApplication
()
.
statusBarHidden
=
true
}
else
{
UIApplication
.
sharedApplication
()
.
statusBarHidden
=
true
==
self
?
.
opened
?
true
:
hide
}
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment