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
beff5c45
Commit
beff5c45
authored
May 10, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-366: added dynamic spacing to NavigationBar
parent
a5d7594f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
54 deletions
+89
-54
Examples/Programmatic/App/App.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/App/App/AppNavigationController.swift
+0
-1
Sources/iOS/MaterialLayout.swift
+16
-0
Sources/iOS/NavigationBar.swift
+66
-21
Sources/iOS/NavigationItem.swift
+1
-32
No files found.
Examples/Programmatic/App/App.xcodeproj/project.pbxproj
View file @
beff5c45
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
/* Begin PBXBuildFile section */
96162C6C1CA71C8700E3A235
/* VideoViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96162C6B1CA71C8700E3A235
/* VideoViewController.swift */
;
};
96162C6C1CA71C8700E3A235
/* VideoViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96162C6B1CA71C8700E3A235
/* VideoViewController.swift */
;
};
96162C6E1CA7274E00E3A235
/* PhotoViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96162C6D1CA7274E00E3A235
/* PhotoViewController.swift */
;
};
96162C6E1CA7274E00E3A235
/* PhotoViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96162C6D1CA7274E00E3A235
/* PhotoViewController.swift */
;
};
961F192F1CE14C3E008927C5
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
961F192E1CE14C3E008927C5
/* Material.framework */
;
};
961F19301CE14C3E008927C5
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
961F192E1CE14C3E008927C5
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
9663F9321C7A744600AF0965
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9311C7A744600AF0965
/* AppDelegate.swift */
;
};
9663F9321C7A744600AF0965
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9311C7A744600AF0965
/* AppDelegate.swift */
;
};
9663F9341C7A744600AF0965
/* RecommendationViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9331C7A744600AF0965
/* RecommendationViewController.swift */
;
};
9663F9341C7A744600AF0965
/* RecommendationViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9331C7A744600AF0965
/* RecommendationViewController.swift */
;
};
9663F9391C7A744600AF0965
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9381C7A744600AF0965
/* Assets.xcassets */
;
};
9663F9391C7A744600AF0965
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9663F9381C7A744600AF0965
/* Assets.xcassets */
;
};
...
@@ -28,6 +30,7 @@
...
@@ -28,6 +30,7 @@
dstPath
=
""
;
dstPath
=
""
;
dstSubfolderSpec
=
10
;
dstSubfolderSpec
=
10
;
files
=
(
files
=
(
961F19301CE14C3E008927C5
/* Material.framework in Embed Frameworks */
,
);
);
name
=
"Embed Frameworks"
;
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
...
@@ -37,6 +40,7 @@
...
@@ -37,6 +40,7 @@
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
96162C6B1CA71C8700E3A235
/* VideoViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
VideoViewController.swift
;
sourceTree
=
"<group>"
;
};
96162C6B1CA71C8700E3A235
/* VideoViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
VideoViewController.swift
;
sourceTree
=
"<group>"
;
};
96162C6D1CA7274E00E3A235
/* PhotoViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
PhotoViewController.swift
;
sourceTree
=
"<group>"
;
};
96162C6D1CA7274E00E3A235
/* PhotoViewController.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
PhotoViewController.swift
;
sourceTree
=
"<group>"
;
};
961F192E1CE14C3E008927C5
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
9663F92E1C7A744600AF0965
/* App.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
App.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
9663F92E1C7A744600AF0965
/* App.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
App.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
9663F9311C7A744600AF0965
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
9663F9311C7A744600AF0965
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
9663F9331C7A744600AF0965
/* RecommendationViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
RecommendationViewController.swift
;
sourceTree
=
"<group>"
;
};
9663F9331C7A744600AF0965
/* RecommendationViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
RecommendationViewController.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -56,6 +60,7 @@
...
@@ -56,6 +60,7 @@
isa
=
PBXFrameworksBuildPhase
;
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
961F192F1CE14C3E008927C5
/* Material.framework in Frameworks */
,
);
);
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
};
};
...
@@ -65,6 +70,7 @@
...
@@ -65,6 +70,7 @@
9663F9251C7A744500AF0965
=
{
9663F9251C7A744500AF0965
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
961F192E1CE14C3E008927C5
/* Material.framework */
,
9663F9301C7A744600AF0965
/* App */
,
9663F9301C7A744600AF0965
/* App */
,
9663F92F1C7A744600AF0965
/* Products */
,
9663F92F1C7A744600AF0965
/* Products */
,
);
);
...
...
Examples/Programmatic/App/App/AppNavigationController.swift
View file @
beff5c45
...
@@ -44,7 +44,6 @@ class AppNavigationController: NavigationController {
...
@@ -44,7 +44,6 @@ class AppNavigationController: NavigationController {
override
func
viewWillLayoutSubviews
()
{
override
func
viewWillLayoutSubviews
()
{
super
.
viewWillLayoutSubviews
()
super
.
viewWillLayoutSubviews
()
statusBarView
?
.
hidden
=
MaterialDevice
.
statusBarHidden
statusBarView
?
.
hidden
=
MaterialDevice
.
statusBarHidden
print
(
MaterialDevice
.
statusBarHidden
)
}
}
/// Prepares the statusBarView
/// Prepares the statusBarView
...
...
Sources/iOS/MaterialLayout.swift
View file @
beff5c45
...
@@ -37,6 +37,7 @@ public struct MaterialLayout {
...
@@ -37,6 +37,7 @@ public struct MaterialLayout {
public
static
func
width
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
width
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
let
metrics
:
Dictionary
<
String
,
AnyObject
>
=
[
"width"
:
width
]
let
metrics
:
Dictionary
<
String
,
AnyObject
>
=
[
"width"
:
width
]
let
views
:
Dictionary
<
String
,
AnyObject
>
=
[
"child"
:
child
]
let
views
:
Dictionary
<
String
,
AnyObject
>
=
[
"child"
:
child
]
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"H:[child(width)]"
,
options
:
options
,
metrics
:
metrics
,
views
:
views
))
parent
.
addConstraints
(
constraint
(
"H:[child(width)]"
,
options
:
options
,
metrics
:
metrics
,
views
:
views
))
}
}
...
@@ -46,6 +47,7 @@ public struct MaterialLayout {
...
@@ -46,6 +47,7 @@ public struct MaterialLayout {
public
static
func
height
(
parent
:
UIView
,
child
:
UIView
,
height
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
height
(
parent
:
UIView
,
child
:
UIView
,
height
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
let
metrics
:
Dictionary
<
String
,
AnyObject
>
=
[
"height"
:
height
]
let
metrics
:
Dictionary
<
String
,
AnyObject
>
=
[
"height"
:
height
]
let
views
:
Dictionary
<
String
,
AnyObject
>
=
[
"child"
:
child
]
let
views
:
Dictionary
<
String
,
AnyObject
>
=
[
"child"
:
child
]
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"V:[child(height)]"
,
options
:
options
,
metrics
:
metrics
,
views
:
views
))
parent
.
addConstraints
(
constraint
(
"V:[child(height)]"
,
options
:
options
,
metrics
:
metrics
,
views
:
views
))
}
}
...
@@ -53,6 +55,7 @@ public struct MaterialLayout {
...
@@ -53,6 +55,7 @@ public struct MaterialLayout {
:name: size
:name: size
*/
*/
public
static
func
size
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
height
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
size
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
height
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
width
(
parent
,
child
:
child
,
width
:
width
)
MaterialLayout
.
width
(
parent
,
child
:
child
,
width
:
width
)
MaterialLayout
.
height
(
parent
,
child
:
child
,
height
:
height
)
MaterialLayout
.
height
(
parent
,
child
:
child
,
height
:
height
)
}
}
...
@@ -70,6 +73,7 @@ public struct MaterialLayout {
...
@@ -70,6 +73,7 @@ public struct MaterialLayout {
i
+=
1
i
+=
1
views
[
k
]
=
v
views
[
k
]
=
v
format
+=
i
>
children
.
count
?
"[
\(
k
)
(==view1)]-(right)-|"
:
"[
\(
k
)
(==view1)]-(spacing)-"
format
+=
i
>
children
.
count
?
"[
\(
k
)
(==view1)]-(right)-|"
:
"[
\(
k
)
(==view1)]-(spacing)-"
v
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
parent
.
addConstraints
(
constraint
(
format
,
options
:
options
,
metrics
:
[
"left"
:
left
,
"right"
:
right
,
"spacing"
:
spacing
],
views
:
views
))
parent
.
addConstraints
(
constraint
(
format
,
options
:
options
,
metrics
:
[
"left"
:
left
,
"right"
:
right
,
"spacing"
:
spacing
],
views
:
views
))
}
}
...
@@ -88,6 +92,7 @@ public struct MaterialLayout {
...
@@ -88,6 +92,7 @@ public struct MaterialLayout {
i
+=
1
i
+=
1
views
[
k
]
=
v
views
[
k
]
=
v
format
+=
i
>
children
.
count
?
"[
\(
k
)
(==view1)]-(bottom)-|"
:
"[
\(
k
)
(==view1)]-(spacing)-"
format
+=
i
>
children
.
count
?
"[
\(
k
)
(==view1)]-(bottom)-|"
:
"[
\(
k
)
(==view1)]-(spacing)-"
v
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
parent
.
addConstraints
(
constraint
(
format
,
options
:
options
,
metrics
:
[
"top"
:
top
,
"bottom"
:
bottom
,
"spacing"
:
spacing
],
views
:
views
))
parent
.
addConstraints
(
constraint
(
format
,
options
:
options
,
metrics
:
[
"top"
:
top
,
"bottom"
:
bottom
,
"spacing"
:
spacing
],
views
:
views
))
}
}
...
@@ -97,6 +102,7 @@ public struct MaterialLayout {
...
@@ -97,6 +102,7 @@ public struct MaterialLayout {
:name: alignToParentHorizontally
:name: alignToParentHorizontally
*/
*/
public
static
func
alignToParentHorizontally
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignToParentHorizontally
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"H:|-(left)-[child]-(right)-|"
,
options
:
options
,
metrics
:
[
"left"
:
left
,
"right"
:
right
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"H:|-(left)-[child]-(right)-|"
,
options
:
options
,
metrics
:
[
"left"
:
left
,
"right"
:
right
],
views
:
[
"child"
:
child
]))
}
}
...
@@ -104,6 +110,7 @@ public struct MaterialLayout {
...
@@ -104,6 +110,7 @@ public struct MaterialLayout {
:name: alignToParentVertically
:name: alignToParentVertically
*/
*/
public
static
func
alignToParentVertically
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignToParentVertically
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"V:|-(top)-[child]-(bottom)-|"
,
options
:
options
,
metrics
:
[
"bottom"
:
bottom
,
"top"
:
top
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"V:|-(top)-[child]-(bottom)-|"
,
options
:
options
,
metrics
:
[
"bottom"
:
bottom
,
"top"
:
top
],
views
:
[
"child"
:
child
]))
}
}
...
@@ -111,6 +118,7 @@ public struct MaterialLayout {
...
@@ -111,6 +118,7 @@ public struct MaterialLayout {
:name: alignToParent
:name: alignToParent
*/
*/
public
static
func
alignToParent
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignToParent
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
alignToParentHorizontally
(
parent
,
child
:
child
,
left
:
left
,
right
:
right
)
alignToParentHorizontally
(
parent
,
child
:
child
,
left
:
left
,
right
:
right
)
alignToParentVertically
(
parent
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
alignToParentVertically
(
parent
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
}
}
...
@@ -119,6 +127,7 @@ public struct MaterialLayout {
...
@@ -119,6 +127,7 @@ public struct MaterialLayout {
:name: alignFromTopLeft
:name: alignFromTopLeft
*/
*/
public
static
func
alignFromTopLeft
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromTopLeft
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
}
...
@@ -127,6 +136,7 @@ public struct MaterialLayout {
...
@@ -127,6 +136,7 @@ public struct MaterialLayout {
:name: alignFromTopRight
:name: alignFromTopRight
*/
*/
public
static
func
alignFromTopRight
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromTopRight
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
}
...
@@ -135,6 +145,7 @@ public struct MaterialLayout {
...
@@ -135,6 +145,7 @@ public struct MaterialLayout {
:name: alignFromBottomLeft
:name: alignFromBottomLeft
*/
*/
public
static
func
alignFromBottomLeft
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromBottomLeft
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
}
...
@@ -143,6 +154,7 @@ public struct MaterialLayout {
...
@@ -143,6 +154,7 @@ public struct MaterialLayout {
:name: alignFromBottomRight
:name: alignFromBottomRight
*/
*/
public
static
func
alignFromBottomRight
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromBottomRight
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
}
...
@@ -151,6 +163,7 @@ public struct MaterialLayout {
...
@@ -151,6 +163,7 @@ public struct MaterialLayout {
:name: alignFromTop
:name: alignFromTop
*/
*/
public
static
func
alignFromTop
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromTop
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"V:|-(top)-[child]"
,
options
:
options
,
metrics
:
[
"top"
:
top
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"V:|-(top)-[child]"
,
options
:
options
,
metrics
:
[
"top"
:
top
],
views
:
[
"child"
:
child
]))
}
}
...
@@ -158,6 +171,7 @@ public struct MaterialLayout {
...
@@ -158,6 +171,7 @@ public struct MaterialLayout {
:name: alignFromLeft
:name: alignFromLeft
*/
*/
public
static
func
alignFromLeft
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromLeft
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"H:|-(left)-[child]"
,
options
:
options
,
metrics
:
[
"left"
:
left
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"H:|-(left)-[child]"
,
options
:
options
,
metrics
:
[
"left"
:
left
],
views
:
[
"child"
:
child
]))
}
}
...
@@ -165,6 +179,7 @@ public struct MaterialLayout {
...
@@ -165,6 +179,7 @@ public struct MaterialLayout {
:name: alignFromBottom
:name: alignFromBottom
*/
*/
public
static
func
alignFromBottom
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromBottom
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"V:[child]-(bottom)-|"
,
options
:
options
,
metrics
:
[
"bottom"
:
bottom
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"V:[child]-(bottom)-|"
,
options
:
options
,
metrics
:
[
"bottom"
:
bottom
],
views
:
[
"child"
:
child
]))
}
}
...
@@ -172,6 +187,7 @@ public struct MaterialLayout {
...
@@ -172,6 +187,7 @@ public struct MaterialLayout {
:name: alignFromRight
:name: alignFromRight
*/
*/
public
static
func
alignFromRight
(
parent
:
UIView
,
child
:
UIView
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
public
static
func
alignFromRight
(
parent
:
UIView
,
child
:
UIView
,
right
:
CGFloat
=
0
,
options
:
NSLayoutFormatOptions
=
[])
{
child
.
translatesAutoresizingMaskIntoConstraints
=
false
parent
.
addConstraints
(
constraint
(
"H:[child]-(right)-|"
,
options
:
options
,
metrics
:
[
"right"
:
right
],
views
:
[
"child"
:
child
]))
parent
.
addConstraints
(
constraint
(
"H:[child]-(right)-|"
,
options
:
options
,
metrics
:
[
"right"
:
right
],
views
:
[
"child"
:
child
]))
}
}
...
...
Sources/iOS/NavigationBar.swift
View file @
beff5c45
...
@@ -44,6 +44,12 @@ public extension UINavigationBar {
...
@@ -44,6 +44,12 @@ public extension UINavigationBar {
@IBDesignable
@IBDesignable
public
class
NavigationBar
:
UINavigationBar
{
public
class
NavigationBar
:
UINavigationBar
{
/// The current layout.
private
var
isLandscape
:
Bool
=
false
/// the spacer inset value.
private
var
spacerInset
:
CGFloat
=
0
/// Left spacer moves the items to the left edge of the NavigationBar.
/// Left spacer moves the items to the left edge of the NavigationBar.
private
var
leftSpacer
:
UIBarButtonItem
=
UIBarButtonItem
(
barButtonSystemItem
:
.
FixedSpace
,
target
:
nil
,
action
:
nil
)
private
var
leftSpacer
:
UIBarButtonItem
=
UIBarButtonItem
(
barButtonSystemItem
:
.
FixedSpace
,
target
:
nil
,
action
:
nil
)
...
@@ -261,12 +267,29 @@ public class NavigationBar : UINavigationBar {
...
@@ -261,12 +267,29 @@ public class NavigationBar : UINavigationBar {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
if
!
isLandscape
&&
MaterialDevice
.
isLandscape
{
isLandscape
=
true
spacerInset
=
0
}
else
if
isLandscape
&&
MaterialDevice
.
isPortrait
{
isLandscape
=
false
spacerInset
=
0
}
if
let
v
:
UINavigationItem
=
topItem
{
if
let
v
:
UINavigationItem
=
topItem
{
sizeNavigationItem
(
v
)
if
0
==
spacerInset
{
layoutNavigationItem
(
v
)
}
else
{
sizeNavigationItem
(
v
)
}
}
}
if
let
v
:
UINavigationItem
=
backItem
{
if
let
v
:
UINavigationItem
=
backItem
{
sizeNavigationItem
(
v
)
if
0
==
spacerInset
{
layoutNavigationItem
(
v
)
}
else
{
sizeNavigationItem
(
v
)
}
}
}
}
}
...
@@ -284,19 +307,23 @@ public class NavigationBar : UINavigationBar {
...
@@ -284,19 +307,23 @@ public class NavigationBar : UINavigationBar {
// leftControls
// leftControls
if
let
v
:
Array
<
UIControl
>
=
item
.
leftControls
{
if
let
v
:
Array
<
UIControl
>
=
item
.
leftControls
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
if
0
<
v
.
count
{
for
c
in
v
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
for
c
in
v
{
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
}
n
.
append
(
leftSpacer
)
item
.
leftBarButtonItems
=
n
.
reverse
()
if
0
==
spacerInset
{
spacerInset
=
n
.
first
!.
customView
!.
frame
.
origin
.
x
}
}
}
n
.
append
(
leftSpacer
)
item
.
leftBarButtonItems
=
n
.
reverse
()
}
}
// Set the titleView if title is empty.
// Set the titleView if title is empty.
if
""
==
item
.
title
{
if
""
==
item
.
title
{
if
nil
==
item
.
titleView
{
if
nil
==
item
.
titleView
{
item
.
titleView
=
UIView
(
frame
:
CGRectMake
(
0
,
contentInset
.
top
,
MaterialDevice
.
width
<
MaterialDevice
.
height
?
MaterialDevice
.
height
:
MaterialDevice
.
width
,
intrinsicContentSize
()
.
height
-
contentInset
.
top
-
contentInset
.
bottom
))
item
.
titleView
=
UIView
(
frame
:
CGRectMake
(
0
,
contentInset
.
top
,
MaterialDevice
.
width
<
MaterialDevice
.
height
?
MaterialDevice
.
height
:
MaterialDevice
.
width
,
intrinsicContentSize
()
.
height
-
contentInset
.
top
-
contentInset
.
bottom
))
item
.
titleView
!.
autoresizingMask
=
[
.
FlexibleWidth
]
item
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
item
.
titleView
!.
grid
.
axis
.
direction
=
.
Vertical
}
}
...
@@ -321,15 +348,19 @@ public class NavigationBar : UINavigationBar {
...
@@ -321,15 +348,19 @@ public class NavigationBar : UINavigationBar {
// rightControls
// rightControls
if
let
v
:
Array
<
UIControl
>
=
item
.
rightControls
{
if
let
v
:
Array
<
UIControl
>
=
item
.
rightControls
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
if
0
<
v
.
count
{
for
c
in
v
{
var
n
:
Array
<
UIBarButtonItem
>
=
Array
<
UIBarButtonItem
>
()
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
for
c
in
v
{
n
.
append
(
UIBarButtonItem
(
customView
:
c
))
}
n
.
append
(
rightSpacer
)
item
.
rightBarButtonItems
=
n
.
reverse
()
if
0
==
spacerInset
{
spacerInset
=
width
-
n
[
n
.
count
-
2
]
.
customView
!.
frame
.
origin
.
x
-
n
[
n
.
count
-
2
]
.
customView
!.
frame
.
width
}
}
}
n
.
append
(
rightSpacer
)
item
.
rightBarButtonItems
=
n
.
reverse
()
}
}
sizeNavigationItem
(
item
)
sizeNavigationItem
(
item
)
}
}
...
@@ -338,9 +369,11 @@ public class NavigationBar : UINavigationBar {
...
@@ -338,9 +369,11 @@ public class NavigationBar : UINavigationBar {
- Parameter item: A UINavigationItem to size.
- Parameter item: A UINavigationItem to size.
*/
*/
internal
func
sizeNavigationItem
(
item
:
UINavigationItem
)
{
internal
func
sizeNavigationItem
(
item
:
UINavigationItem
)
{
print
(
spacerInset
)
let
h
:
CGFloat
=
intrinsicContentSize
()
.
height
let
h
:
CGFloat
=
intrinsicContentSize
()
.
height
let
w
:
CGFloat
=
backButton
.
intrinsicContentSize
()
.
width
var
spaceLeft
:
CGFloat
=
0
let
inset
:
CGFloat
=
MaterialDevice
.
isLandscape
?
item
.
landscapeInset
:
item
.
portraitInset
var
spaceRight
:
CGFloat
=
0
var
capturedSpace
:
Bool
=
false
// leftControls
// leftControls
if
let
v
:
Array
<
UIControl
>
=
item
.
leftControls
{
if
let
v
:
Array
<
UIControl
>
=
item
.
leftControls
{
...
@@ -349,9 +382,12 @@ public class NavigationBar : UINavigationBar {
...
@@ -349,9 +382,12 @@ public class NavigationBar : UINavigationBar {
b
.
contentEdgeInsets
.
top
=
0
b
.
contentEdgeInsets
.
top
=
0
b
.
contentEdgeInsets
.
bottom
=
0
b
.
contentEdgeInsets
.
bottom
=
0
}
}
c
.
bounds
.
size
=
c
is
MaterialSwitch
?
CGSizeMake
(
w
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
:
CGSizeMake
(
c
.
intrinsicContentSize
()
.
width
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
c
.
bounds
.
size
=
CGSizeMake
(
c
.
intrinsicContentSize
()
.
width
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
c
.
backgroundColor
=
MaterialColor
.
purple
.
base
spaceLeft
+=
c
.
bounds
.
size
.
width
+
contentInset
.
left
}
}
leftSpacer
.
width
=
inset
+
contentInset
.
left
leftSpacer
.
width
=
contentInset
.
left
-
spacerInset
spaceLeft
+=
contentInset
.
left
}
}
item
.
titleView
?
.
frame
.
size
.
width
=
width
item
.
titleView
?
.
frame
.
size
.
width
=
width
...
@@ -382,10 +418,18 @@ public class NavigationBar : UINavigationBar {
...
@@ -382,10 +418,18 @@ public class NavigationBar : UINavigationBar {
b
.
contentEdgeInsets
.
top
=
0
b
.
contentEdgeInsets
.
top
=
0
b
.
contentEdgeInsets
.
bottom
=
0
b
.
contentEdgeInsets
.
bottom
=
0
}
}
c
.
bounds
.
size
=
c
is
MaterialSwitch
?
CGSizeMake
(
w
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
:
CGSizeMake
(
c
.
intrinsicContentSize
()
.
width
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
c
.
bounds
.
size
=
CGSizeMake
(
c
.
intrinsicContentSize
()
.
width
,
h
-
contentInset
.
top
-
contentInset
.
bottom
)
c
.
backgroundColor
=
MaterialColor
.
purple
.
base
.
colorWithAlphaComponent
(
0.1
)
spaceRight
+=
c
.
bounds
.
size
.
width
+
contentInset
.
right
}
}
rightSpacer
.
width
=
inset
+
contentInset
.
right
rightSpacer
.
width
=
contentInset
.
right
-
spacerInset
spaceRight
+=
contentInset
.
right
}
}
item
.
titleView
?
.
backgroundColor
=
MaterialColor
.
green
.
base
item
.
titleView
?
.
frame
.
size
.
width
=
width
-
spaceLeft
-
spaceRight
item
.
titleView
?
.
frame
.
origin
.
x
=
spaceLeft
item
.
titleView
?
.
grid
.
reloadLayout
()
}
}
/**
/**
...
@@ -396,6 +440,7 @@ public class NavigationBar : UINavigationBar {
...
@@ -396,6 +440,7 @@ public class NavigationBar : UINavigationBar {
when subclassing.
when subclassing.
*/
*/
public
func
prepareView
()
{
public
func
prepareView
()
{
isLandscape
=
MaterialDevice
.
isLandscape
barStyle
=
.
Default
barStyle
=
.
Default
translucent
=
false
translucent
=
false
backButtonImage
=
nil
backButtonImage
=
nil
...
...
Sources/iOS/NavigationItem.swift
View file @
beff5c45
...
@@ -34,12 +34,6 @@ import UIKit
...
@@ -34,12 +34,6 @@ import UIKit
private
var
MaterialAssociatedObjectNavigationItemKey
:
UInt8
=
0
private
var
MaterialAssociatedObjectNavigationItemKey
:
UInt8
=
0
public
class
MaterialAssociatedObjectNavigationItem
{
public
class
MaterialAssociatedObjectNavigationItem
{
/// Portrait inset.
public
var
portraitInset
:
CGFloat
/// Landscape inset.
public
var
landscapeInset
:
CGFloat
/// Detail View.
/// Detail View.
public
var
detailView
:
UIView
?
public
var
detailView
:
UIView
?
...
@@ -54,11 +48,6 @@ public class MaterialAssociatedObjectNavigationItem {
...
@@ -54,11 +48,6 @@ public class MaterialAssociatedObjectNavigationItem {
/// Right controls.
/// Right controls.
public
var
rightControls
:
Array
<
UIControl
>
?
public
var
rightControls
:
Array
<
UIControl
>
?
public
init
(
portraitInset
:
CGFloat
,
landscapeInset
:
CGFloat
)
{
self
.
portraitInset
=
portraitInset
self
.
landscapeInset
=
landscapeInset
}
}
}
public
extension
UINavigationItem
{
public
extension
UINavigationItem
{
...
@@ -66,7 +55,7 @@ public extension UINavigationItem {
...
@@ -66,7 +55,7 @@ public extension UINavigationItem {
public
internal(set)
var
item
:
MaterialAssociatedObjectNavigationItem
{
public
internal(set)
var
item
:
MaterialAssociatedObjectNavigationItem
{
get
{
get
{
return
MaterialAssociatedObject
(
self
,
key
:
&
MaterialAssociatedObjectNavigationItemKey
)
{
return
MaterialAssociatedObject
(
self
,
key
:
&
MaterialAssociatedObjectNavigationItemKey
)
{
return
MaterialAssociatedObjectNavigationItem
(
portraitInset
:
.
iPad
==
MaterialDevice
.
type
||
"iPhone 6s Plus"
==
MaterialDevice
.
model
||
"iPhone 6 Plus"
==
MaterialDevice
.
model
?
-
20
:
-
16
,
landscapeInset
:
-
20
)
return
MaterialAssociatedObjectNavigationItem
()
}
}
}
}
set
(
value
)
{
set
(
value
)
{
...
@@ -74,26 +63,6 @@ public extension UINavigationItem {
...
@@ -74,26 +63,6 @@ public extension UINavigationItem {
}
}
}
}
/// Portrait inset.
public
var
portraitInset
:
CGFloat
{
get
{
return
item
.
portraitInset
}
set
(
value
)
{
item
.
portraitInset
=
value
}
}
/// Landscape inset.
public
var
landscapeInset
:
CGFloat
{
get
{
return
item
.
landscapeInset
}
set
(
value
)
{
item
.
landscapeInset
=
value
}
}
/// Detail View.
/// Detail View.
public
var
detailView
:
UIView
?
{
public
var
detailView
:
UIView
?
{
get
{
get
{
...
...
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