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
8e91d135
Commit
8e91d135
authored
Oct 19, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup internally in Layout class
parent
a6f0225a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
52 deletions
+27
-52
Sources/iOS/Layout.swift
+27
-52
No files found.
Sources/iOS/Layout.swift
View file @
8e91d135
...
...
@@ -629,6 +629,19 @@ public class Layout {
}
}
fileprivate
extension
Layout
{
/**
Updates and lays out the constraints for a given view.
- Parameter for view: A UIView.
*/
class
func
updateConstraints
(
for
view
:
UIView
)
{
view
.
updateConstraintsIfNeeded
()
view
.
updateConstraints
()
view
.
setNeedsLayout
()
view
.
layoutIfNeeded
()
}
}
/// Layout
extension
Layout
{
/**
...
...
@@ -640,9 +653,7 @@ extension Layout {
public
class
func
width
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
width
,
relatedBy
:
.
equal
,
toItem
:
nil
,
attribute
:
.
width
,
multiplier
:
1
,
constant
:
width
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -654,9 +665,7 @@ extension Layout {
public
class
func
height
(
parent
:
UIView
,
child
:
UIView
,
height
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
height
,
relatedBy
:
.
equal
,
toItem
:
nil
,
attribute
:
.
height
,
multiplier
:
1
,
constant
:
height
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -681,6 +690,7 @@ extension Layout {
*/
public
class
func
horizontally
(
parent
:
UIView
,
children
:
[
UIView
],
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
interimSpace
:
InterimSpace
=
0
)
{
prepareForConstraint
(
parent
,
children
:
children
)
if
0
<
children
.
count
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
0
],
attribute
:
.
left
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
left
,
multiplier
:
1
,
constant
:
left
))
for
i
in
1
..<
children
.
count
{
...
...
@@ -689,10 +699,9 @@ extension Layout {
}
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
children
.
count
-
1
],
attribute
:
.
right
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
right
,
multiplier
:
1
,
constant
:
-
right
))
}
for
child
in
children
{
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
}
...
...
@@ -718,9 +727,7 @@ extension Layout {
}
for
child
in
children
{
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
}
...
...
@@ -733,13 +740,9 @@ extension Layout {
*/
public
class
func
horizontally
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
left
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
left
,
multiplier
:
1
,
constant
:
left
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
right
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
right
,
multiplier
:
1
,
constant
:
-
right
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -751,13 +754,9 @@ extension Layout {
*/
public
class
func
vertically
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
top
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
top
,
multiplier
:
1
,
constant
:
top
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
bottom
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
bottom
,
multiplier
:
1
,
constant
:
-
bottom
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -783,12 +782,8 @@ extension Layout {
*/
public
class
func
top
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
top
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
top
,
multiplier
:
1
,
constant
:
top
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -800,12 +795,8 @@ extension Layout {
*/
public
class
func
left
(
parent
:
UIView
,
child
:
UIView
,
left
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
left
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
left
,
multiplier
:
1
,
constant
:
left
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -817,12 +808,8 @@ extension Layout {
*/
public
class
func
bottom
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
bottom
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
bottom
,
multiplier
:
1
,
constant
:
-
bottom
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -834,12 +821,8 @@ extension Layout {
*/
public
class
func
right
(
parent
:
UIView
,
child
:
UIView
,
right
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
right
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
right
,
multiplier
:
1
,
constant
:
-
right
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -916,12 +899,8 @@ extension Layout {
*/
public
class
func
centerHorizontally
(
parent
:
UIView
,
child
:
UIView
,
offset
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
centerX
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
centerX
,
multiplier
:
1
,
constant
:
offset
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
@@ -933,12 +912,8 @@ extension Layout {
*/
public
class
func
centerVertically
(
parent
:
UIView
,
child
:
UIView
,
offset
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
centerY
,
relatedBy
:
.
equal
,
toItem
:
parent
,
attribute
:
.
centerY
,
multiplier
:
1
,
constant
:
offset
))
child
.
updateConstraints
()
child
.
setNeedsLayout
()
child
.
layoutIfNeeded
()
updateConstraints
(
for
:
child
)
}
/**
...
...
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