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
77e68079
Commit
77e68079
authored
Mar 05, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added custom leftControls and rightControls
parent
3f8dc4cc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
24 deletions
+100
-24
Examples/Programmatic/App/App/FeedViewController.swift
+24
-4
Examples/Programmatic/App/App/ViewController.swift
+5
-0
Sources/NavigationBar.swift
+64
-20
Sources/NavigationController.swift
+7
-0
No files found.
Examples/Programmatic/App/App/FeedViewController.swift
View file @
77e68079
...
@@ -52,10 +52,10 @@ class FeedViewController: UIViewController {
...
@@ -52,10 +52,10 @@ class FeedViewController: UIViewController {
override
func
viewWillAppear
(
animated
:
Bool
)
{
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
super
.
viewWillAppear
(
animated
)
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
navigationController
?
.
navigationBar
.
backgroundColor
=
MaterialColor
.
blue
.
base
let
image
=
UIImage
(
named
:
"ic_menu_white"
)
navigationItem
.
title
=
"Feed"
var
image
=
UIImage
(
named
:
"ic_menu_white"
)
// Menu button.
// Menu button.
let
menuButton
:
FlatButton
=
FlatButton
()
let
menuButton
:
FlatButton
=
FlatButton
()
...
@@ -65,16 +65,36 @@ class FeedViewController: UIViewController {
...
@@ -65,16 +65,36 @@ class FeedViewController: UIViewController {
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
menuButton
.
addTarget
(
self
,
action
:
"handleMenuButton"
,
forControlEvents
:
.
TouchUpInside
)
menuButton
.
addTarget
(
self
,
action
:
"handleMenuButton"
,
forControlEvents
:
.
TouchUpInside
)
navigationController
?
.
navigationBar
.
rightControls
=
[
menuButton
]
// Switch control.
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Small
)
// Search button.
image
=
UIImage
(
named
:
"ic_search_white"
)
let
searchButton
:
FlatButton
=
FlatButton
()
searchButton
.
pulseColor
=
MaterialColor
.
white
searchButton
.
pulseScale
=
false
searchButton
.
setImage
(
image
,
forState
:
.
Normal
)
searchButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
searchButton
.
addTarget
(
self
,
action
:
"handleSearchButton"
,
forControlEvents
:
.
TouchUpInside
)
navigationController
?
.
navigationBar
.
leftControls
=
[
menuButton
]
navigationController
?
.
navigationBar
.
rightControls
=
[
switchControl
,
searchButton
]
}
}
internal
func
handleMenuButton
()
{
internal
func
handleMenuButton
()
{
print
(
"handled"
)
print
(
"handled"
)
}
}
internal
func
handleSearchButton
()
{
print
(
"handled"
)
}
/// Prepares view.
/// Prepares view.
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
navigationController
?
.
navigationBar
.
backgroundColor
=
MaterialColor
.
blue
.
base
}
}
/// Prepares the collectionView
/// Prepares the collectionView
...
...
Examples/Programmatic/App/App/ViewController.swift
View file @
77e68079
...
@@ -43,6 +43,11 @@ class ViewController: UIViewController {
...
@@ -43,6 +43,11 @@ class ViewController: UIViewController {
override
func
viewWillAppear
(
animated
:
Bool
)
{
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
super
.
viewWillAppear
(
animated
)
navigationItem
.
title
=
"Material"
navigationController
?
.
navigationBar
.
leftControls
=
[]
navigationController
?
.
navigationBar
.
rightControls
=
[]
}
}
/// Prepares view.
/// Prepares view.
...
...
Sources/NavigationBar.swift
View file @
77e68079
...
@@ -34,15 +34,26 @@ import UIKit
...
@@ -34,15 +34,26 @@ import UIKit
private
var
NavigationBarKey
:
UInt8
=
0
private
var
NavigationBarKey
:
UInt8
=
0
public
class
Controls
{
public
class
Controls
{
/// A preset wrapper around contentInset.
public
var
contentInsetPreset
:
MaterialEdgeInset
/// A wrapper around grid.contentInset.
public
var
contentInset
:
UIEdgeInsets
/// Left controls.
/// Left controls.
public
var
leftControls
:
Array
<
UIControl
>
?
public
var
leftControls
:
Array
<
UIControl
>
?
/// Right controls.
/// Right controls.
public
var
rightControls
:
Array
<
UIControl
>
?
public
var
rightControls
:
Array
<
UIControl
>
?
public
init
()
{
contentInsetPreset
=
.
Square3
contentInset
=
MaterialEdgeInsetToValue
(
.
Square3
)
}
}
}
public
extension
UINavigationBar
{
public
extension
UINavigationBar
{
///
Grid
reference.
///
Controls
reference.
public
var
controls
:
Controls
{
public
var
controls
:
Controls
{
get
{
get
{
return
MaterialObjectAssociatedObject
(
self
,
key
:
&
NavigationBarKey
)
{
return
MaterialObjectAssociatedObject
(
self
,
key
:
&
NavigationBarKey
)
{
...
@@ -54,15 +65,6 @@ public extension UINavigationBar {
...
@@ -54,15 +65,6 @@ public extension UINavigationBar {
}
}
}
}
public
var
title
:
String
?
{
get
{
return
topItem
?
.
title
}
set
(
value
)
{
topItem
?
.
title
=
value
}
}
/// Device status bar style.
/// Device status bar style.
public
var
statusBarStyle
:
UIStatusBarStyle
{
public
var
statusBarStyle
:
UIStatusBarStyle
{
get
{
get
{
...
@@ -81,14 +83,22 @@ public extension UINavigationBar {
...
@@ -81,14 +83,22 @@ public extension UINavigationBar {
var
c
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
var
c
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
if
let
v
:
Array
<
UIControl
>
=
value
{
if
let
v
:
Array
<
UIControl
>
=
value
{
for
q
in
v
{
for
q
in
v
{
let
b
:
UIBarButtonItem
=
UIBarButtonItem
(
customView
:
q
)
if
let
p
:
UIButton
=
q
as?
UIButton
{
b
.
width
=
q
.
intrinsicContentSize
()
.
width
p
.
frame
.
size
=
CGSizeMake
(
40
,
28
)
c
.
append
(
b
)
p
.
contentEdgeInsets
=
UIEdgeInsetsZero
c
.
append
(
UIBarButtonItem
(
customView
:
p
))
}
else
{
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
controls
.
leftControls
=
value
topItem
?
.
leftBarButtonItems
=
c
topItem
?
.
leftBarButtonItems
=
c
.
reverse
()
}
}
}
}
...
@@ -100,19 +110,47 @@ public extension UINavigationBar {
...
@@ -100,19 +110,47 @@ public extension UINavigationBar {
var
c
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
var
c
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
if
let
v
:
Array
<
UIControl
>
=
value
{
if
let
v
:
Array
<
UIControl
>
=
value
{
for
q
in
v
{
for
q
in
v
{
let
b
:
UIBarButtonItem
=
UIBarButtonItem
(
customView
:
q
)
if
let
p
:
UIButton
=
q
as?
UIButton
{
b
.
width
=
q
.
intrinsicContentSize
()
.
width
p
.
frame
.
size
=
CGSizeMake
(
40
,
28
)
c
.
append
(
b
)
p
.
contentEdgeInsets
=
UIEdgeInsetsZero
c
.
append
(
UIBarButtonItem
(
customView
:
p
))
}
else
{
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
controls
.
rightControls
=
value
topItem
?
.
rightBarButtonItems
=
c
topItem
?
.
rightBarButtonItems
=
c
.
reverse
()
}
}
}
}
}
}
public
class
NavigationBar
:
UINavigationBar
{
public
class
NavigationBar
:
UINavigationBar
{
/// 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
}
}
/**
/**
The back button image writes to the backIndicatorImage property and
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
backIndicatorTransitionMaskImage property.
...
@@ -223,5 +261,11 @@ public class NavigationBar : UINavigationBar {
...
@@ -223,5 +261,11 @@ public class NavigationBar : UINavigationBar {
backButtonImage
=
nil
backButtonImage
=
nil
backgroundColor
=
MaterialColor
.
white
backgroundColor
=
MaterialColor
.
white
depth
=
.
Depth1
depth
=
.
Depth1
titleTextAttributes
=
[
NSFontAttributeName
:
RobotoFont
.
regularWithSize
(
20
)]
}
public
func
reloadView
()
{
leftControls
=
controls
.
leftControls
rightControls
=
controls
.
rightControls
}
}
}
}
Sources/NavigationController.swift
View file @
77e68079
...
@@ -56,4 +56,11 @@ public class NavigationController : UINavigationController {
...
@@ -56,4 +56,11 @@ public class NavigationController : UINavigationController {
public
func
prepareView
()
{
public
func
prepareView
()
{
navigationItem
.
title
=
"Title"
navigationItem
.
title
=
"Title"
}
}
public
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
if
let
v
:
NavigationBar
=
navigationBar
as?
NavigationBar
{
v
.
reloadView
()
}
}
}
}
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