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
17733f51
Commit
17733f51
authored
Feb 25, 2018
by
intoxicated
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed iOS 11 navigationBar layoutMargin to zero
parent
0eb7acf7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
156 deletions
+162
-156
Sources/iOS/NavigationBar.swift
+162
-156
No files found.
Sources/iOS/NavigationBar.swift
View file @
17733f51
...
@@ -31,177 +31,183 @@
...
@@ -31,177 +31,183 @@
import
UIKit
import
UIKit
open
class
NavigationBar
:
UINavigationBar
{
open
class
NavigationBar
:
UINavigationBar
{
/// Will layout the view.
/// Will layout the view.
open
var
willLayout
:
Bool
{
open
var
willLayout
:
Bool
{
return
0
<
bounds
.
width
&&
0
<
bounds
.
height
&&
nil
!=
superview
return
0
<
bounds
.
width
&&
0
<
bounds
.
height
&&
nil
!=
superview
}
/// Detail UILabel when in landscape for iOS 11.
fileprivate
var
toolbarToText
:
[
Toolbar
:
String
?]?
open
override
var
intrinsicContentSize
:
CGSize
{
return
CGSize
(
width
:
bounds
.
width
,
height
:
bounds
.
height
)
}
/// A preset wrapper around contentEdgeInsets.
open
var
contentEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
didSet
{
contentEdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
}
}
}
/// Detail UILabel when in landscape for iOS 11.
fileprivate
var
toolbarToText
:
[
Toolbar
:
String
?]?
/// A reference to EdgeInsets.
@IBInspectable
open
override
var
intrinsicContentSize
:
CGSize
{
open
var
contentEdgeInsets
=
EdgeInsets
.
zero
{
return
CGSize
(
width
:
bounds
.
width
,
height
:
bounds
.
height
)
didSet
{
layoutSubviews
()
}
}
/// A preset wrapper around interimSpace.
open
var
interimSpacePreset
=
InterimSpacePreset
.
interimSpace3
{
didSet
{
interimSpace
=
InterimSpacePresetToValue
(
preset
:
interimSpacePreset
)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open
var
interimSpace
:
InterimSpace
=
0
{
didSet
{
layoutSubviews
()
}
}
/**
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
*/
@IBInspectable
open
var
backButtonImage
:
UIImage
?
{
get
{
return
backIndicatorImage
}
set
(
value
)
{
let
image
:
UIImage
?
=
value
backIndicatorImage
=
image
backIndicatorTransitionMaskImage
=
image
}
}
/// A property that accesses the backing layer's background
@IBInspectable
open
override
var
backgroundColor
:
UIColor
?
{
get
{
return
barTintColor
}
}
set
(
value
)
{
barTintColor
=
value
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepare
()
}
/**
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
)
{
super
.
init
(
frame
:
frame
)
prepare
()
}
/// A convenience initializer.
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
}
open
override
func
sizeThatFits
(
_
size
:
CGSize
)
->
CGSize
{
return
intrinsicContentSize
}
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
layoutShape
()
layoutShadowPath
()
//
/ A preset wrapper around contentEdgeInsets.
//
iOS 11 added left/right layout margin in subviews of UINavigationBar
open
var
contentEdgeInsetsPreset
=
EdgeInsetsPreset
.
none
{
//since we do not want to unsafely access private view directly
didSet
{
//iterate subviews to set `layoutMargin` to zero
contentEdgeInsets
=
EdgeInsetsPresetToValue
(
preset
:
contentEdgeInsetsPreset
)
for
view
in
subviews
{
}
view
.
layoutMargins
=
.
zero
}
}
/// A reference to EdgeInsets.
if
let
v
=
topItem
{
@IBInspectable
layoutNavigationItem
(
item
:
v
)
open
var
contentEdgeInsets
=
EdgeInsets
.
zero
{
didSet
{
layoutSubviews
()
}
}
}
/// A preset wrapper around interimSpace.
if
let
v
=
backItem
{
open
var
interimSpacePreset
=
InterimSpacePreset
.
interimSpace3
{
layoutNavigationItem
(
item
:
v
)
didSet
{
interimSpace
=
InterimSpacePresetToValue
(
preset
:
interimSpacePreset
)
}
}
}
layoutDivider
()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open
func
prepare
()
{
barStyle
=
.
black
isTranslucent
=
false
depthPreset
=
.
none
contentScaleFactor
=
Screen
.
scale
contentEdgeInsetsPreset
=
.
none
interimSpacePreset
=
.
none
backButtonImage
=
Icon
.
cm
.
arrowBack
/// A wrapper around grid.interimSpace.
if
#available(iOS 11, *)
{
@IBInspectable
toolbarToText
=
[:]
open
var
interimSpace
:
InterimSpace
=
0
{
didSet
{
layoutSubviews
()
}
}
}
/**
The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property.
*/
@IBInspectable
open
var
backButtonImage
:
UIImage
?
{
get
{
return
backIndicatorImage
}
set
(
value
)
{
let
image
:
UIImage
?
=
value
backIndicatorImage
=
image
backIndicatorTransitionMaskImage
=
image
}
}
/// A property that accesses the backing layer's background
@IBInspectable
open
override
var
backgroundColor
:
UIColor
?
{
get
{
return
barTintColor
}
set
(
value
)
{
barTintColor
=
value
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepare
()
}
/**
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
)
{
super
.
init
(
frame
:
frame
)
prepare
()
}
/// A convenience initializer.
public
convenience
init
()
{
self
.
init
(
frame
:
.
zero
)
}
open
override
func
sizeThatFits
(
_
size
:
CGSize
)
->
CGSize
{
return
intrinsicContentSize
}
open
override
func
layoutSubviews
()
{
let
image
=
UIImage
()
super
.
layoutSubviews
()
shadowImage
=
image
layoutShape
()
setBackgroundImage
(
image
,
for
:
.
default
)
layoutShadowPath
()
backgroundColor
=
.
white
}
if
let
v
=
topItem
{
layoutNavigationItem
(
item
:
v
)
}
if
let
v
=
backItem
{
layoutNavigationItem
(
item
:
v
)
}
layoutDivider
()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open
func
prepare
()
{
barStyle
=
.
black
isTranslucent
=
false
depthPreset
=
.
depth1
contentScaleFactor
=
Screen
.
scale
contentEdgeInsetsPreset
=
.
square1
interimSpacePreset
=
.
interimSpace3
backButtonImage
=
Icon
.
cm
.
arrowBack
if
#available(iOS 11, *)
{
toolbarToText
=
[:]
}
let
image
=
UIImage
()
shadowImage
=
image
setBackgroundImage
(
image
,
for
:
.
default
)
backgroundColor
=
.
white
}
}
}
internal
extension
NavigationBar
{
internal
extension
NavigationBar
{
/**
/**
Lays out the UINavigationItem.
Lays out the UINavigationItem.
- Parameter item: A UINavigationItem to layout.
- Parameter item: A UINavigationItem to layout.
*/
*/
func
layoutNavigationItem
(
item
:
UINavigationItem
)
{
func
layoutNavigationItem
(
item
:
UINavigationItem
)
{
guard
willLayout
else
{
guard
willLayout
else
{
return
return
}
}
let
toolbar
=
item
.
toolbar
let
toolbar
=
item
.
toolbar
toolbar
.
backgroundColor
=
.
clear
toolbar
.
backgroundColor
=
.
clear
toolbar
.
interimSpace
=
interimSpace
toolbar
.
interimSpace
=
interimSpace
toolbar
.
contentEdgeInsets
=
contentEdgeInsets
toolbar
.
contentEdgeInsets
=
contentEdgeInsets
if
#available(iOS 11, *)
{
if
Application
.
shouldStatusBarBeHidden
{
toolbar
.
contentEdgeInsetsPreset
=
.
none
if
#available(iOS 11, *)
{
if
nil
!=
toolbar
.
detailLabel
.
text
{
if
Application
.
shouldStatusBarBeHidden
{
toolbarToText
?[
toolbar
]
=
toolbar
.
detailLabel
.
text
toolbar
.
contentEdgeInsetsPreset
=
.
none
toolbar
.
detailLabel
.
text
=
nil
if
nil
!=
toolbar
.
detailLabel
.
text
{
toolbarToText
?[
toolbar
]
=
toolbar
.
detailLabel
.
text
toolbar
.
detailLabel
.
text
=
nil
}
}
else
if
nil
!=
toolbarToText
?[
toolbar
]
{
toolbar
.
detailLabel
.
text
=
toolbarToText
?[
toolbar
]
??
nil
toolbarToText
?[
toolbar
]
=
nil
}
}
}
}
else
if
nil
!=
toolbarToText
?[
toolbar
]
{
item
.
titleView
=
toolbar
toolbar
.
detailLabel
.
text
=
toolbarToText
?[
toolbar
]
??
nil
item
.
titleView
!.
frame
=
bounds
toolbarToText
?[
toolbar
]
=
nil
}
}
}
item
.
titleView
=
toolbar
item
.
titleView
!.
frame
=
bounds
}
}
}
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