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
8ce9ef8a
Commit
8ce9ef8a
authored
Mar 06, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added titleLabel and detailLabel to NavigationBar
parent
9b9bd858
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
163 additions
and
51 deletions
+163
-51
Examples/Programmatic/App/App/FeedViewController.swift
+12
-6
Examples/Programmatic/App/App/InboxViewController.swift
+13
-2
Examples/Programmatic/App/App/MessagesViewController.swift
+13
-2
Sources/NavigationBar.swift
+125
-41
No files found.
Examples/Programmatic/App/App/FeedViewController.swift
View file @
8ce9ef8a
...
@@ -72,13 +72,19 @@ class FeedViewController: UIViewController {
...
@@ -72,13 +72,19 @@ class FeedViewController: UIViewController {
prepareMenuButton
()
prepareMenuButton
()
prepareSearchButton
()
prepareSearchButton
()
// navigationItem.title = "Feed"
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"Material"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
text
=
"Build Beautiful Software"
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
detailLabel
=
detailLabel
var
label
:
UILabel
=
UILabel
()
label
.
text
=
"Daniel"
navigationItem
.
titleView
?
.
addSubview
(
label
)
navigationController
?
.
navigationBar
.
leftControls
=
[
menuButton
]
navigationController
?
.
navigationBar
.
leftControls
=
[
menuButton
]
navigationController
?
.
navigationBar
.
rightControls
=
[
searchButton
]
navigationController
?
.
navigationBar
.
rightControls
=
[
searchButton
]
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
...
...
Examples/Programmatic/App/App/InboxViewController.swift
View file @
8ce9ef8a
...
@@ -46,8 +46,8 @@ class InboxViewController: UIViewController {
...
@@ -46,8 +46,8 @@ class InboxViewController: UIViewController {
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareItems
()
prepareItems
()
prepareView
()
prepareTableView
()
prepareTableView
()
}
}
...
@@ -68,7 +68,18 @@ class InboxViewController: UIViewController {
...
@@ -68,7 +68,18 @@ class InboxViewController: UIViewController {
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
view
.
backgroundColor
=
MaterialColor
.
white
navigationItem
.
title
=
"Inbox"
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"Inbox"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
text
=
"
\(
items
.
count
)
Contacts"
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
detailLabel
=
detailLabel
}
}
/// Prepares the items Array.
/// Prepares the items Array.
...
...
Examples/Programmatic/App/App/MessagesViewController.swift
View file @
8ce9ef8a
...
@@ -46,8 +46,8 @@ class MessagesViewController: UIViewController {
...
@@ -46,8 +46,8 @@ class MessagesViewController: UIViewController {
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareItems
()
prepareItems
()
prepareView
()
prepareTableView
()
prepareTableView
()
}
}
...
@@ -68,7 +68,18 @@ class MessagesViewController: UIViewController {
...
@@ -68,7 +68,18 @@ class MessagesViewController: UIViewController {
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
view
.
backgroundColor
=
MaterialColor
.
white
navigationItem
.
title
=
"Messages"
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"Messages"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
text
=
"
\(
items
.
count
)
Messages"
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
detailLabel
=
detailLabel
}
}
/// Prepares the items Array.
/// Prepares the items Array.
...
...
Sources/NavigationBar.swift
View file @
8ce9ef8a
...
@@ -374,53 +374,87 @@ public class NavigationBar : UINavigationBar {
...
@@ -374,53 +374,87 @@ public class NavigationBar : UINavigationBar {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
if
1
<
width
{
// Size of single grid column.
// Size of single grid column.
if
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
axis
.
columns
?
grid
.
axis
.
columns
:
1
)
{
if
let
g
:
CGFloat
=
width
/
CGFloat
(
0
<
grid
.
axis
.
columns
?
grid
.
axis
.
columns
:
1
)
{
grid
.
views
=
[]
grid
.
views
=
[]
grid
.
axis
.
columns
=
Int
(
width
/
48
)
grid
.
axis
.
columns
=
Int
(
width
/
48
)
var
columns
:
Int
=
grid
.
axis
.
columns
var
columns
:
Int
=
grid
.
axis
.
columns
// leftControls
// leftControls
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
if
let
v
:
Array
<
UIControl
>
=
leftControls
{
for
c
in
v
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
let
b
:
UIButton
=
c
as?
UIButton
{
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
columns
-=
c
.
grid
.
columns
grid
.
views
?
.
append
(
c
)
}
}
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
columns
-=
c
.
grid
.
columns
grid
.
views
?
.
append
(
c
)
}
}
}
if
nil
==
topItem
?
.
titleView
{
topItem
?
.
titleView
=
MaterialView
()
if
let
v
:
UINavigationItem
=
topItem
{
topItem
?
.
titleView
?
.
backgroundColor
=
nil
if
nil
==
v
.
titleView
{
if
nil
!=
backItem
{
let
button
:
FlatButton
=
FlatButton
()
button
.
setImage
(
backButtonImage
,
forState
:
.
Normal
)
button
.
setImage
(
backButtonImage
,
forState
:
.
Highlighted
)
v
.
backBarButtonItem
=
UIBarButtonItem
(
customView
:
button
)
backItem
?
.
title
=
""
}
v
.
titleView
=
UIView
()
}
}
grid
.
views
?
.
append
(
topItem
!.
titleView
!
)
// rightControls
v
.
titleView
!.
backgroundColor
=
nil
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
v
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
for
c
in
v
{
v
.
titleView
!.
grid
.
views
=
[]
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
let
b
:
UIButton
=
c
as?
UIButton
{
// TitleView alignment.
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
if
let
t
:
UILabel
=
v
.
titleLabel
{
}
v
.
titleView
!.
addSubview
(
t
)
v
.
titleView
!.
grid
.
views
?
.
append
(
t
)
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
if
let
d
:
UILabel
=
v
.
detailLabel
{
columns
-=
c
.
grid
.
columns
v
.
titleView
!.
addSubview
(
d
)
v
.
titleView
!.
grid
.
views
?
.
append
(
d
)
grid
.
views
?
.
append
(
c
)
t
.
grid
.
rows
=
2
t
.
font
=
t
.
font
.
fontWithSize
(
17
)
d
.
grid
.
rows
=
2
d
.
font
=
d
.
font
.
fontWithSize
(
12
)
v
.
titleView
!.
grid
.
axis
.
rows
=
3
v
.
titleView
!.
grid
.
spacing
=
-
8
v
.
titleView
!.
grid
.
contentInset
.
top
=
-
8
}
else
{
t
.
grid
.
rows
=
1
t
.
font
=
t
.
font
?
.
fontWithSize
(
20
)
v
.
titleView
!.
grid
.
axis
.
rows
=
1
v
.
titleView
!.
grid
.
spacing
=
0
v
.
titleView
!.
grid
.
contentInset
.
top
=
0
}
}
}
}
topItem
?
.
titleView
?
.
grid
.
columns
=
columns
// rightControls?.first?.grid.offset.columns = columns
grid
.
reloadLayout
()
grid
.
views
?
.
append
(
v
.
titleView
!
)
}
// rightControls
if
let
v
:
Array
<
UIControl
>
=
rightControls
{
for
c
in
v
{
let
w
:
CGFloat
=
c
.
intrinsicContentSize
()
.
width
if
let
b
:
UIButton
=
c
as?
UIButton
{
b
.
contentEdgeInsets
=
UIEdgeInsetsZero
}
c
.
grid
.
columns
=
0
==
g
?
1
:
Int
(
ceil
(
w
/
g
))
columns
-=
c
.
grid
.
columns
grid
.
views
?
.
append
(
c
)
}
}
}
topItem
?
.
titleView
?
.
grid
.
columns
=
columns
grid
.
reloadLayout
()
topItem
?
.
titleView
?
.
grid
.
reloadLayout
()
}
}
}
}
...
@@ -438,7 +472,9 @@ public class NavigationBar : UINavigationBar {
...
@@ -438,7 +472,9 @@ public class NavigationBar : UINavigationBar {
backButtonImage
=
nil
backButtonImage
=
nil
backgroundColor
=
MaterialColor
.
white
backgroundColor
=
MaterialColor
.
white
depth
=
.
Depth1
depth
=
.
Depth1
contentInsetPreset
=
.
None
spacingPreset
=
.
Spacing2
contentInsetPreset
=
.
Square2
contentInset
.
left
=
100
titleTextAttributes
=
[
NSFontAttributeName
:
RobotoFont
.
regularWithSize
(
20
)]
titleTextAttributes
=
[
NSFontAttributeName
:
RobotoFont
.
regularWithSize
(
20
)]
setTitleVerticalPositionAdjustment
(
1
,
forBarMetrics
:
.
Default
)
setTitleVerticalPositionAdjustment
(
1
,
forBarMetrics
:
.
Default
)
setTitleVerticalPositionAdjustment
(
2
,
forBarMetrics
:
.
Compact
)
setTitleVerticalPositionAdjustment
(
2
,
forBarMetrics
:
.
Compact
)
...
@@ -469,7 +505,7 @@ public class NavigationBar : UINavigationBar {
...
@@ -469,7 +505,7 @@ public class NavigationBar : UINavigationBar {
}
}
}
}
/// A memory reference to the
Grid instance for UIView
extensions.
/// A memory reference to the
NavigationBarControls instance for UINavigationBar
extensions.
private
var
NavigationBarKey
:
UInt8
=
0
private
var
NavigationBarKey
:
UInt8
=
0
public
class
NavigationBarControls
{
public
class
NavigationBarControls
{
...
@@ -480,6 +516,20 @@ public class NavigationBarControls {
...
@@ -480,6 +516,20 @@ public class NavigationBarControls {
public
var
rightControls
:
Array
<
UIControl
>
?
public
var
rightControls
:
Array
<
UIControl
>
?
}
}
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
private
var
NavigationItemKey
:
UInt8
=
0
public
class
NavigationItemLabels
{
/// Title view.
public
var
titleView
:
UIView
?
/// Title label.
public
var
titleLabel
:
UILabel
?
/// Detail label.
public
var
detailLabel
:
UILabel
?
}
public
extension
UINavigationBar
{
public
extension
UINavigationBar
{
/// Device status bar style.
/// Device status bar style.
public
var
statusBarStyle
:
UIStatusBarStyle
{
public
var
statusBarStyle
:
UIStatusBarStyle
{
...
@@ -579,3 +629,37 @@ public extension UINavigationBar {
...
@@ -579,3 +629,37 @@ public extension UINavigationBar {
}
}
}
}
}
}
public
extension
UINavigationItem
{
/// NavigationBarControls reference.
public
internal(set)
var
labels
:
NavigationItemLabels
{
get
{
return
MaterialAssociatedObject
(
self
,
key
:
&
NavigationItemKey
)
{
return
NavigationItemLabels
()
}
}
set
(
value
)
{
MaterialAssociateObject
(
self
,
key
:
&
NavigationItemKey
,
value
:
value
)
}
}
/// Title Label.
public
var
titleLabel
:
UILabel
?
{
get
{
return
labels
.
titleLabel
}
set
(
value
)
{
labels
.
titleLabel
=
value
}
}
/// Detail Label.
public
var
detailLabel
:
UILabel
?
{
get
{
return
labels
.
detailLabel
}
set
(
value
)
{
labels
.
detailLabel
=
value
}
}
}
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