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
28bbe4cb
Commit
28bbe4cb
authored
Mar 06, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working titleView for NavigationBar
parent
8ce9ef8a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
139 deletions
+142
-139
Examples/Programmatic/App/App/AppDelegate.swift
+1
-1
Examples/Programmatic/App/App/AppNavigationBarViewController.swift
+117
-75
Examples/Programmatic/App/App/FeedViewController.swift
+0
-36
Sources/NavigationBar.swift
+24
-27
No files found.
Examples/Programmatic/App/App/AppDelegate.swift
View file @
28bbe4cb
...
@@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
...
@@ -40,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.
// Override point for customization after application launch.
window
=
UIWindow
(
frame
:
UIScreen
.
mainScreen
()
.
bounds
)
window
=
UIWindow
(
frame
:
UIScreen
.
mainScreen
()
.
bounds
)
// window!.rootViewController = SideNavigationViewController(mainViewController: AppMenuViewController(mainViewController: AppNavigationBarViewController(mainViewController: InboxViewController())), leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
// window!.rootViewController = SideNavigationViewController(mainViewController: AppMenuViewController(mainViewController: AppNavigationBarViewController(mainViewController: InboxViewController())), leftViewController: AppLeftViewController(), rightViewController: AppRightViewController())
window
!.
rootViewController
=
SideNavigationViewController
(
mainViewController
:
AppMenuViewController
(
mainViewController
:
NavigationController
(
rootViewController
:
FeedViewController
())),
leftViewController
:
AppLeftViewController
())
window
!.
rootViewController
=
SideNavigationViewController
(
mainViewController
:
AppMenuViewController
(
mainViewController
:
App
NavigationController
(
rootViewController
:
FeedViewController
())),
leftViewController
:
AppLeftViewController
())
window
!.
makeKeyAndVisible
()
window
!.
makeKeyAndVisible
()
return
true
return
true
}
}
...
...
Examples/Programmatic/App/App/AppNavigationBarViewController.swift
View file @
28bbe4cb
...
@@ -36,98 +36,140 @@ flow of your application.
...
@@ -36,98 +36,140 @@ flow of your application.
import
UIKit
import
UIKit
import
Material
import
Material
class
AppNavigationBarViewController
:
NavigationBarViewController
{
class
AppNavigationController
:
NavigationController
{
override
var
floatingViewController
:
UIViewController
?
{
/// Menu button at the top left of the navigation bar.
didSet
{
private
lazy
var
menuButton
:
FlatButton
=
FlatButton
()
if
nil
==
floatingViewController
{
navigationBarView
.
statusBarStyle
=
.
LightContent
/// Search button at the top left of the navigation bar.
}
private
lazy
var
searchButton
:
FlatButton
=
FlatButton
()
}
}
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareNavigationBarView
()
}
override
func
viewWillAppear
(
animated
:
Bool
)
{
super
.
viewWillAppear
(
animated
)
navigationBarView
.
statusBarStyle
=
.
LightContent
}
/// Prepares view.
prepareMenuButton
()
override
func
prepareView
()
{
prepareSearchButton
()
super
.
prepareView
()
view
.
backgroundColor
=
MaterialColor
.
black
navigationBarViewController
?
.
delegate
=
self
}
/// Toggle SideNavigationViewController left UIViewController.
internal
func
handleMenuButton
()
{
sideNavigationViewController
?
.
toggleLeftView
()
}
/// Toggle SideNavigationViewController right UIViewController.
navigationBar
.
leftControls
=
[
menuButton
]
internal
func
handleSearchButton
()
{
navigationBar
.
rightControls
=
[
searchButton
]
floatingViewController
=
AppSearchBarViewController
(
mainViewController
:
SearchListViewController
())
navigationBar
.
statusBarStyle
=
.
LightContent
navigationBar
.
tintColor
=
MaterialColor
.
white
navigationBar
.
backgroundColor
=
MaterialColor
.
blue
.
base
}
}
/// Prepares the navigationBarView.
/// Prepares the menuButton.
private
func
prepareNavigationBarView
()
{
private
func
prepareMenuButton
()
{
// Title label.
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_menu_white"
)
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
var
image
=
UIImage
(
named
:
"ic_menu_white"
)
// Menu button.
let
menuButton
:
FlatButton
=
FlatButton
()
menuButton
.
pulseColor
=
MaterialColor
.
white
menuButton
.
pulseScale
=
false
menuButton
.
pulseScale
=
false
menuButton
.
pulseColor
=
MaterialColor
.
white
menuButton
.
setImage
(
image
,
forState
:
.
Normal
)
menuButton
.
setImage
(
image
,
forState
:
.
Normal
)
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
menuButton
.
addTarget
(
self
,
action
:
"handleMenuButton"
,
forControlEvents
:
.
TouchUpInside
)
menuButton
.
addTarget
(
self
,
action
:
"handleMenuButton"
,
forControlEvents
:
.
TouchUpInside
)
}
// Switch control.
/// Prepares the searchButton.
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Small
)
private
func
prepareSearchButton
()
{
// Search button.
// Search button.
image
=
UIImage
(
named
:
"ic_search_white"
)
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_search_white"
)
let
searchButton
:
FlatButton
=
FlatButton
()
searchButton
.
pulseColor
=
MaterialColor
.
white
searchButton
.
pulseScale
=
false
searchButton
.
pulseScale
=
false
searchButton
.
pulseColor
=
MaterialColor
.
white
searchButton
.
setImage
(
image
,
forState
:
.
Normal
)
searchButton
.
setImage
(
image
,
forState
:
.
Normal
)
searchButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
searchButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
searchButton
.
addTarget
(
self
,
action
:
"handleSearchButton"
,
forControlEvents
:
.
TouchUpInside
)
searchButton
.
addTarget
(
self
,
action
:
"handleSearchButton"
,
forControlEvents
:
.
TouchUpInside
)
navigationBarView
.
backgroundColor
=
MaterialColor
.
blue
.
base
navigationBarView
.
titleLabel
=
titleLabel
navigationBarView
.
leftControls
=
[
menuButton
]
navigationBarView
.
rightControls
=
[
switchControl
,
searchButton
]
}
}
}
}
//class AppNavigationBarViewController: NavigationBarViewController {
extension
AppNavigationBarViewController
:
NavigationBarViewControllerDelegate
{
// override var floatingViewController: UIViewController? {
/// Delegation method that executes when the floatingViewController will open.
// didSet {
func
navigationBarViewControllerWillOpenFloatingViewController
(
navigationBarViewController
:
NavigationBarViewController
)
{
// if nil == floatingViewController {
print
(
"Will Open"
)
// navigationBarView.statusBarStyle = .LightContent
}
// }
// }
/// Delegation method that executes when the floatingViewController will close.
// }
func
navigationBarViewControllerWillCloseFloatingViewController
(
navigationBarViewController
:
NavigationBarViewController
)
{
//
print
(
"Will Close"
)
// override func viewDidLoad() {
}
// super.viewDidLoad()
// prepareView()
/// Delegation method that executes when the floatingViewController did open.
// prepareNavigationBarView()
func
navigationBarViewControllerDidOpenFloatingViewController
(
navigationBarViewController
:
NavigationBarViewController
)
{
// }
print
(
"Did Open"
)
//
}
// override func viewWillAppear(animated: Bool) {
// super.viewWillAppear(animated)
/// Delegation method that executes when the floatingViewController did close.
// navigationBarView.statusBarStyle = .LightContent
func
navigationBarViewControllerDidCloseFloatingViewController
(
navigationBarViewController
:
NavigationBarViewController
)
{
// }
print
(
"Did Close"
)
//
}
// /// Prepares view.
}
// override func prepareView() {
// super.prepareView()
// view.backgroundColor = MaterialColor.black
// navigationBarViewController?.delegate = self
// }
//
// /// Toggle SideNavigationViewController left UIViewController.
// internal func handleMenuButton() {
// sideNavigationViewController?.toggleLeftView()
// }
//
// /// Toggle SideNavigationViewController right UIViewController.
// internal func handleSearchButton() {
// floatingViewController = AppSearchBarViewController(mainViewController: SearchListViewController())
// }
//
// /// Prepares the navigationBarView.
// private func prepareNavigationBarView() {
// // Title label.
// let titleLabel: UILabel = UILabel()
// titleLabel.textAlignment = .Left
// titleLabel.textColor = MaterialColor.white
//
// var image = UIImage(named: "ic_menu_white")
//
// // Menu button.
// let menuButton: FlatButton = FlatButton()
// menuButton.pulseColor = MaterialColor.white
// menuButton.pulseScale = false
// menuButton.setImage(image, forState: .Normal)
// menuButton.setImage(image, forState: .Highlighted)
// menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
//
// // 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)
//
// navigationBarView.backgroundColor = MaterialColor.blue.base
// navigationBarView.titleLabel = titleLabel
// navigationBarView.leftControls = [menuButton]
// navigationBarView.rightControls = [switchControl, searchButton]
// }
//}
//
//
//extension AppNavigationBarViewController: NavigationBarViewControllerDelegate {
// /// Delegation method that executes when the floatingViewController will open.
// func navigationBarViewControllerWillOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Will Open")
// }
//
// /// Delegation method that executes when the floatingViewController will close.
// func navigationBarViewControllerWillCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Will Close")
// }
//
// /// Delegation method that executes when the floatingViewController did open.
// func navigationBarViewControllerDidOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Did Open")
// }
//
// /// Delegation method that executes when the floatingViewController did close.
// func navigationBarViewControllerDidCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
// print("Did Close")
// }
//}
Examples/Programmatic/App/App/FeedViewController.swift
View file @
28bbe4cb
...
@@ -32,12 +32,6 @@ import UIKit
...
@@ -32,12 +32,6 @@ import UIKit
import
Material
import
Material
class
FeedViewController
:
UIViewController
{
class
FeedViewController
:
UIViewController
{
/// Menu button at the top left of the navigation bar.
private
lazy
var
menuButton
:
FlatButton
=
FlatButton
()
/// Search button at the top left of the navigation bar.
private
lazy
var
searchButton
:
FlatButton
=
FlatButton
()
/// MaterialCollectionView.
/// MaterialCollectionView.
private
lazy
var
collectionView
:
MaterialCollectionView
=
MaterialCollectionView
()
private
lazy
var
collectionView
:
MaterialCollectionView
=
MaterialCollectionView
()
...
@@ -69,9 +63,6 @@ class FeedViewController: UIViewController {
...
@@ -69,9 +63,6 @@ class FeedViewController: UIViewController {
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
view
.
backgroundColor
=
MaterialColor
.
grey
.
lighten4
prepareMenuButton
()
prepareSearchButton
()
let
titleLabel
:
UILabel
=
UILabel
()
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"Material"
titleLabel
.
text
=
"Material"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textAlignment
=
.
Left
...
@@ -84,33 +75,6 @@ class FeedViewController: UIViewController {
...
@@ -84,33 +75,6 @@ class FeedViewController: UIViewController {
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
titleLabel
=
titleLabel
navigationItem
.
detailLabel
=
detailLabel
navigationItem
.
detailLabel
=
detailLabel
navigationController
?
.
navigationBar
.
leftControls
=
[
menuButton
]
navigationController
?
.
navigationBar
.
rightControls
=
[
searchButton
]
navigationController
?
.
navigationBar
.
statusBarStyle
=
.
LightContent
navigationController
?
.
navigationBar
.
tintColor
=
MaterialColor
.
white
navigationController
?
.
navigationBar
.
backgroundColor
=
MaterialColor
.
blue
.
base
}
/// Prepares the menuButton.
private
func
prepareMenuButton
()
{
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_menu_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
)
}
/// Prepares the searchButton.
private
func
prepareSearchButton
()
{
// Search button.
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_search_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
)
}
}
/// Prepares the collectionView
/// Prepares the collectionView
...
...
Sources/NavigationBar.swift
View file @
28bbe4cb
...
@@ -374,6 +374,8 @@ public class NavigationBar : UINavigationBar {
...
@@ -374,6 +374,8 @@ public class NavigationBar : UINavigationBar {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
backItem
?
.
title
=
""
// 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
=
[]
...
@@ -397,18 +399,11 @@ public class NavigationBar : UINavigationBar {
...
@@ -397,18 +399,11 @@ public class NavigationBar : UINavigationBar {
if
let
v
:
UINavigationItem
=
topItem
{
if
let
v
:
UINavigationItem
=
topItem
{
if
nil
==
v
.
titleView
{
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
()
v
.
titleView
=
UIView
()
}
v
.
titleView
!.
backgroundColor
=
nil
v
.
titleView
!.
backgroundColor
=
nil
v
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
v
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
}
v
.
titleView
!.
grid
.
views
=
[]
v
.
titleView
!.
grid
.
views
=
[]
// TitleView alignment.
// TitleView alignment.
...
@@ -454,7 +449,6 @@ public class NavigationBar : UINavigationBar {
...
@@ -454,7 +449,6 @@ public class NavigationBar : UINavigationBar {
topItem
?
.
titleView
?
.
grid
.
columns
=
columns
topItem
?
.
titleView
?
.
grid
.
columns
=
columns
grid
.
reloadLayout
()
grid
.
reloadLayout
()
topItem
?
.
titleView
?
.
grid
.
reloadLayout
()
}
}
}
}
...
@@ -472,9 +466,7 @@ public class NavigationBar : UINavigationBar {
...
@@ -472,9 +466,7 @@ public class NavigationBar : UINavigationBar {
backButtonImage
=
nil
backButtonImage
=
nil
backgroundColor
=
MaterialColor
.
white
backgroundColor
=
MaterialColor
.
white
depth
=
.
Depth1
depth
=
.
Depth1
spacingPreset
=
.
Spacing2
contentInset
=
UIEdgeInsetsMake
(
8
,
0
,
8
,
0
)
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
)
...
@@ -516,20 +508,6 @@ public class NavigationBarControls {
...
@@ -516,20 +508,6 @@ 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
{
...
@@ -606,6 +584,10 @@ public extension UINavigationBar {
...
@@ -606,6 +584,10 @@ public extension UINavigationBar {
}
}
}
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12
// c.append(spacer)
controls
.
leftControls
=
value
controls
.
leftControls
=
value
topItem
?
.
leftBarButtonItems
=
c
.
reverse
()
topItem
?
.
leftBarButtonItems
=
c
.
reverse
()
}
}
...
@@ -624,12 +606,27 @@ public extension UINavigationBar {
...
@@ -624,12 +606,27 @@ public extension UINavigationBar {
}
}
}
}
// let spacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
// spacer.width = -12
// c.append(spacer)
controls
.
rightControls
=
value
controls
.
rightControls
=
value
topItem
?
.
rightBarButtonItems
=
c
.
reverse
()
topItem
?
.
rightBarButtonItems
=
c
.
reverse
()
}
}
}
}
}
}
/// A memory reference to the NavigationItemLabels instance for UINavigationItem extensions.
private
var
NavigationItemKey
:
UInt8
=
0
public
class
NavigationItemLabels
{
/// Title label.
public
var
titleLabel
:
UILabel
?
/// Detail label.
public
var
detailLabel
:
UILabel
?
}
public
extension
UINavigationItem
{
public
extension
UINavigationItem
{
/// NavigationBarControls reference.
/// NavigationBarControls reference.
public
internal(set)
var
labels
:
NavigationItemLabels
{
public
internal(set)
var
labels
:
NavigationItemLabels
{
...
...
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