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
7ddb1213
Commit
7ddb1213
authored
Mar 07, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NavigationBar working with dynamic controls
parent
ff3b0d89
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
75 deletions
+64
-75
Examples/Programmatic/App/App/AppNavigationController.swift
+1
-2
Examples/Programmatic/App/App/FeedViewController.swift
+2
-2
Examples/Programmatic/App/App/InboxViewController.swift
+11
-1
Sources/NavigationBar.swift
+44
-50
Sources/NavigationController.swift
+6
-20
No files found.
Examples/Programmatic/App/App/AppNavigationController.swift
View file @
7ddb1213
...
...
@@ -36,8 +36,7 @@ flow of your application.
import
UIKit
import
Material
class
AppNavigationController
:
NavigationController
{
class
AppNavigationController
:
NavigationController
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
Examples/Programmatic/App/App/FeedViewController.swift
View file @
7ddb1213
...
...
@@ -74,12 +74,12 @@ class FeedViewController: UIViewController {
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"Material"
titleLabel
.
text
=
"Material
yyppgg
"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
text
=
"Build Beautiful Software"
detailLabel
.
text
=
"Build Beautiful Software
yyppgg
"
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
...
...
Examples/Programmatic/App/App/InboxViewController.swift
View file @
7ddb1213
...
...
@@ -78,8 +78,18 @@ class InboxViewController: UIViewController {
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Small
)
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_share_white"
)
let
shareButton
:
FlatButton
=
FlatButton
()
shareButton
.
pulseScale
=
false
shareButton
.
pulseColor
=
MaterialColor
.
white
shareButton
.
setImage
(
image
,
forState
:
.
Normal
)
shareButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
detailLabel
=
detailLabel
// navigationItem.detailLabel = detailLabel
navigationItem
.
rightControls
=
[
switchControl
,
shareButton
]
}
/// Prepares the items Array.
...
...
Sources/NavigationBar.swift
View file @
7ddb1213
...
...
@@ -31,6 +31,9 @@
import
UIKit
public
class
NavigationBar
:
UINavigationBar
{
/// Reference to the backButton.
public
private(set)
lazy
var
backButton
:
FlatButton
=
FlatButton
()
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
...
...
@@ -369,38 +372,27 @@ public class NavigationBar : UINavigationBar {
}
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
topItem
?
.
titleView
?
.
grid
.
reloadLayout
()
}
public
func
layoutNavigationItem
(
item
:
UINavigationItem
)
{
grid
.
views
=
[]
grid
.
axis
.
columns
=
Int
(
width
/
48
)
let
g
:
CGFloat
=
width
/
CGFloat
(
grid
.
axis
.
columns
)
var
columns
:
Int
=
grid
.
axis
.
columns
// leftControls
if
let
v
:
Array
<
UIControl
>
=
item
.
leftControls
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
for
c
in
v
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
c
.
intrinsicContentSize
()
.
width
/
g
))
columns
-=
c
.
grid
.
columns
grid
.
views
!.
append
(
c
)
c
.
bounds
.
size
=
c
is
MaterialSwitch
?
backButton
.
bounds
.
size
:
c
.
intrinsicContentSize
()
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = 0
// c.append(spacer)
let
spacer
:
UIBarButtonItem
=
UIBarButtonItem
(
barButtonSystemItem
:
.
FixedSpace
,
target
:
nil
,
action
:
nil
)
spacer
.
width
=
item
.
inset
n
.
append
(
spacer
)
item
.
leftBarButtonItems
=
n
.
reverse
()
}
if
nil
==
item
.
titleView
{
item
.
titleView
=
UIView
()
item
.
titleView
=
UIView
(
frame
:
CGRectMake
(
0
,
2
,
2000
,
40
)
)
item
.
titleView
!.
backgroundColor
=
nil
item
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
}
...
...
@@ -409,56 +401,36 @@ public class NavigationBar : UINavigationBar {
// TitleView alignment.
if
let
t
:
UILabel
=
item
.
titleLabel
{
t
.
grid
.
rows
=
1
item
.
titleView
!.
addSubview
(
t
)
item
.
titleView
!.
grid
.
views
?
.
append
(
t
)
if
let
d
:
UILabel
=
item
.
detailLabel
{
t
.
grid
.
rows
=
2
t
.
font
=
t
.
font
.
fontWithSize
(
17
)
d
.
grid
.
rows
=
2
d
.
grid
.
rows
=
1
d
.
font
=
d
.
font
.
fontWithSize
(
12
)
item
.
titleView
!.
addSubview
(
d
)
item
.
titleView
!.
grid
.
views
?
.
append
(
d
)
item
.
titleView
!.
grid
.
axis
.
rows
=
3
item
.
titleView
!.
grid
.
spacing
=
-
8
item
.
titleView
!.
grid
.
contentInset
.
top
=
-
8
item
.
titleView
!.
grid
.
axis
.
rows
=
2
}
else
{
t
.
grid
.
rows
=
1
t
.
font
=
t
.
font
?
.
fontWithSize
(
20
)
item
.
titleView
!.
grid
.
axis
.
rows
=
1
item
.
titleView
!.
grid
.
spacing
=
0
item
.
titleView
!.
grid
.
contentInset
.
top
=
0
}
}
grid
.
views
?
.
append
(
item
.
titleView
!
)
// rightControls
if
let
v
:
Array
<
UIControl
>
=
item
.
rightControls
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
for
c
in
v
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
c
.
intrinsicContentSize
()
.
width
/
g
))
columns
-=
c
.
grid
.
columns
grid
.
views
!.
append
(
c
)
c
.
bounds
.
size
=
c
is
MaterialSwitch
?
backButton
.
bounds
.
size
:
c
.
intrinsicContentSize
()
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = 0
// c.append(spacer)
let
spacer
:
UIBarButtonItem
=
UIBarButtonItem
(
barButtonSystemItem
:
.
FixedSpace
,
target
:
nil
,
action
:
nil
)
spacer
.
width
=
item
.
inset
n
.
append
(
spacer
)
item
.
rightBarButtonItems
=
n
.
reverse
()
}
item
.
titleView
!.
grid
.
columns
=
columns
grid
.
reloadLayout
()
item
.
titleView
?
.
grid
.
reloadLayout
()
item
.
titleView
!.
grid
.
reloadLayout
()
}
/**
...
...
@@ -469,7 +441,6 @@ public class NavigationBar : UINavigationBar {
when subclassing.
*/
public
func
prepareView
()
{
prepareVisualLayer
()
barStyle
=
.
Black
translucent
=
false
backButtonImage
=
nil
...
...
@@ -477,6 +448,8 @@ public class NavigationBar : UINavigationBar {
depth
=
.
Depth1
spacingPreset
=
.
Spacing2
contentInset
=
UIEdgeInsetsMake
(
8
,
0
,
8
,
0
)
prepareVisualLayer
()
prepareBackButton
()
}
/// Prepares the visualLayer property.
...
...
@@ -491,6 +464,14 @@ public class NavigationBar : UINavigationBar {
visualLayer
.
frame
=
bounds
visualLayer
.
cornerRadius
=
cornerRadius
}
/// Prepares the backButton.
internal
func
prepareBackButton
()
{
backButton
.
pulseScale
=
false
backButton
.
pulseColor
=
MaterialColor
.
white
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Normal
)
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Highlighted
)
}
/// Sets the shadow path.
internal
func
layoutShadowPath
()
{
...
...
@@ -508,6 +489,9 @@ public class NavigationBar : UINavigationBar {
private
var
NavigationItemControlsKey
:
UInt8
=
0
public
class
NavigationItemControls
{
/// Inset.
public
var
inset
:
CGFloat
=
-
16
/// Left controls.
public
var
leftControls
:
Array
<
UIControl
>
?
...
...
@@ -571,6 +555,16 @@ public extension UINavigationItem {
}
}
/// Inset.
public
var
inset
:
CGFloat
{
get
{
return
controls
.
inset
}
set
(
value
)
{
controls
.
inset
=
value
}
}
/// Left side UIControls.
public
var
leftControls
:
Array
<
UIControl
>
?
{
get
{
...
...
Sources/NavigationController.swift
View file @
7ddb1213
...
...
@@ -30,9 +30,7 @@
import
UIKit
public
class
NavigationController
:
UINavigationController
,
UINavigationBarDelegate
{
public
private(set)
lazy
var
backButton
:
FlatButton
=
FlatButton
()
public
class
NavigationController
:
UINavigationController
{
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
}
...
...
@@ -48,7 +46,6 @@ public class NavigationController : UINavigationController, UINavigationBarDeleg
public
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareBackButton
()
interactivePopGestureRecognizer
?
.
delegate
=
nil
}
...
...
@@ -68,32 +65,21 @@ public class NavigationController : UINavigationController, UINavigationBarDeleg
public
func
navigationBar
(
navigationBar
:
UINavigationBar
,
shouldPushItem
item
:
UINavigationItem
)
->
Bool
{
item
.
title
=
""
item
.
setHidesBackButton
(
true
,
animated
:
false
)
return
true
}
public
func
navigationBar
(
navigationBar
:
UINavigationBar
,
didPushItem
item
:
UINavigationItem
)
{
if
let
v
:
NavigationBar
=
navigationBar
as?
NavigationBar
{
if
var
c
:
Array
<
UIControl
>
=
item
.
leftControls
{
c
.
append
(
backButton
)
c
.
append
(
v
.
backButton
)
item
.
leftControls
=
c
}
else
{
item
.
leftControls
=
[
backButton
]
item
.
leftControls
=
[
v
.
backButton
]
}
v
.
backButton
.
removeTarget
(
self
,
action
:
"handleBackButton"
,
forControlEvents
:
.
TouchUpInside
)
v
.
backButton
.
addTarget
(
self
,
action
:
"handleBackButton"
,
forControlEvents
:
.
TouchUpInside
)
v
.
layoutNavigationItem
(
item
)
}
return
true
}
internal
func
handleBackButton
()
{
popViewControllerAnimated
(
true
)
}
private
func
prepareBackButton
()
{
if
let
v
:
NavigationBar
=
navigationBar
as?
NavigationBar
{
backButton
.
pulseScale
=
false
backButton
.
pulseColor
=
MaterialColor
.
white
backButton
.
setImage
(
v
.
backButtonImage
,
forState
:
.
Normal
)
backButton
.
setImage
(
v
.
backButtonImage
,
forState
:
.
Highlighted
)
backButton
.
addTarget
(
self
,
action
:
"handleBackButton"
,
forControlEvents
:
.
TouchUpInside
)
}
}
}
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