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
e9be01ee
Commit
e9be01ee
authored
Jun 08, 2016
by
danieldahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated Layout API
parent
531a6d39
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
245 additions
and
412 deletions
+245
-412
Examples/Programmatic/App/App/AppLeftViewController.swift
+3
-2
Examples/Programmatic/App/App/AppMenuController.swift
+1
-1
Examples/Programmatic/App/App/RecipesViewController.swift
+2
-2
Examples/Programmatic/App/App/RecommendationViewController.swift
+2
-2
Material.xcodeproj/project.pbxproj
+0
-8
Sources/iOS/Align.swift
+0
-142
Sources/iOS/BottomTabBar.swift
+1
-1
Sources/iOS/CardView.swift
+2
-2
Sources/iOS/ImageCardView.swift
+3
-3
Sources/iOS/Layout.swift
+230
-54
Sources/iOS/MaterialLayout.swift
+0
-194
Sources/iOS/TextView.swift
+1
-1
No files found.
Examples/Programmatic/App/App/AppLeftViewController.swift
View file @
e9be01ee
...
...
@@ -97,9 +97,10 @@ class AppLeftViewController: UIViewController {
nameLabel
.
font
=
RobotoFont
.
mediumWithSize
(
18
)
view
.
layout
.
size
(
profileView
,
width
:
72
,
height
:
72
)
view
.
layout
.
align
FromT
opLeft
(
profileView
,
top
:
30
,
left
:
(
view
.
bounds
.
width
-
72
)
/
2
)
view
.
layout
.
align
.
t
opLeft
(
profileView
,
top
:
30
,
left
:
(
view
.
bounds
.
width
-
72
)
/
2
)
view
.
addSubview
(
nameLabel
)
view
.
layout
.
align
Layout
.
alignFromTop
(
view
,
child
:
nameLabel
,
top
:
130
)
Layout
.
alignToParentHorizontally
(
view
,
child
:
nameLabel
,
left
:
20
,
right
:
20
)
// view.layout.alignFromTop(nameLabel, top: 130)
...
...
@@ -115,7 +116,7 @@ class AppLeftViewController: UIViewController {
tableView
.
separatorStyle
=
.
None
// Use Layout to easily align the tableView.
view
.
layout
.
align
(
tableView
,
top
:
170
)
view
.
layout
.
align
.
edges
(
tableView
,
top
:
170
)
}
}
...
...
Examples/Programmatic/App/App/AppMenuController.swift
View file @
e9be01ee
...
...
@@ -140,7 +140,7 @@ class AppMenuController: MenuController {
menuView
.
delegate
=
self
view
.
layout
.
size
(
menuView
,
width
:
baseSize
.
width
,
height
:
baseSize
.
height
)
view
.
layout
.
align
FromB
ottomRight
(
menuView
,
bottom
:
65
,
right
:
16
)
view
.
layout
.
align
.
b
ottomRight
(
menuView
,
bottom
:
65
,
right
:
16
)
}
}
...
...
Examples/Programmatic/App/App/RecipesViewController.swift
View file @
e9be01ee
...
...
@@ -241,7 +241,7 @@ class RecipesViewController: UIViewController {
tableView
.
delegate
=
self
// Use Layout to easily align the tableView.
view
.
layout
.
align
(
tableView
)
view
.
layout
.
align
.
edges
(
tableView
)
}
}
...
...
@@ -286,7 +286,7 @@ extension RecipesViewController: UITableViewDataSource {
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
text
=
"Favorites"
header
.
layout
.
align
(
label
,
left
:
24
)
header
.
layout
.
align
.
edges
(
label
,
left
:
24
)
return
header
}
...
...
Examples/Programmatic/App/App/RecommendationViewController.swift
View file @
e9be01ee
...
...
@@ -70,7 +70,7 @@ class RecommendationViewController: UIViewController {
tableView
.
delegate
=
self
// Use Layout to easily align the tableView.
view
.
layout
.
align
(
tableView
)
view
.
layout
.
align
.
edges
(
tableView
)
}
}
...
...
@@ -115,7 +115,7 @@ extension RecommendationViewController: UITableViewDataSource {
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
text
=
"Recommendations"
header
.
layout
.
align
(
label
,
left
:
24
)
header
.
layout
.
align
.
edges
(
label
,
left
:
24
)
return
header
}
...
...
Material.xcodeproj/project.pbxproj
View file @
e9be01ee
...
...
@@ -7,8 +7,6 @@
objects
=
{
/* Begin PBXBuildFile section */
65A3F0161D07DBF30047EDD9
/* MaterialLayout.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
65A3F0151D07DBF30047EDD9
/* MaterialLayout.swift */
;
};
65A3F0181D07DBFD0047EDD9
/* Align.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
65A3F0171D07DBFD0047EDD9
/* Align.swift */
;
};
961F18E81CD93E3E008927C5
/* ErrorTextField.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
961F18E71CD93E3E008927C5
/* ErrorTextField.swift */
;
};
96334EF61C8B84660083986B
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96334EF51C8B84660083986B
/* Assets.xcassets */
;
};
963832421B88DFD80015F710
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832361B88DFD80015F710
/* Material.framework */
;
};
...
...
@@ -197,8 +195,6 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
65A3F0151D07DBF30047EDD9
/* MaterialLayout.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialLayout.swift
;
sourceTree
=
"<group>"
;
};
65A3F0171D07DBFD0047EDD9
/* Align.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Align.swift
;
sourceTree
=
"<group>"
;
};
961F18E71CD93E3E008927C5
/* ErrorTextField.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ErrorTextField.swift
;
sourceTree
=
"<group>"
;
};
96334EF51C8B84660083986B
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
963832361B88DFD80015F710
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
includeInIndex
=
0
;
path
=
Material.framework
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
...
...
@@ -483,9 +479,7 @@
96BCB8041CB40F6C00C806FE
/* Layout */
=
{
isa
=
PBXGroup
;
children
=
(
65A3F0151D07DBF30047EDD9
/* MaterialLayout.swift */
,
96BCB7811CB40DC500C806FE
/* Layout.swift */
,
65A3F0171D07DBFD0047EDD9
/* Align.swift */
,
96BCB7611CB40DC500C806FE
/* Grid.swift */
,
);
name
=
Layout
;
...
...
@@ -925,7 +919,6 @@
96BCB7AA1CB40DC500C806FE
/* Grid.swift in Sources */
,
96BCB7E71CB40DC500C806FE
/* TextView.swift in Sources */
,
96BCB7C31CB40DC500C806FE
/* MaterialEdgeInset.swift in Sources */
,
65A3F0161D07DBF30047EDD9
/* MaterialLayout.swift in Sources */
,
96BCB7CE1CB40DC500C806FE
/* MaterialRadius.swift in Sources */
,
96BCB7E11CB40DC500C806FE
/* BarView.swift in Sources */
,
96BCB7A11CB40DC500C806FE
/* BottomNavigationController.swift in Sources */
,
...
...
@@ -941,7 +934,6 @@
96BCB7A61CB40DC500C806FE
/* CardView.swift in Sources */
,
96BCB7C91CB40DC500C806FE
/* MaterialLayer.swift in Sources */
,
96BCB7E21CB40DC500C806FE
/* BarController.swift in Sources */
,
65A3F0181D07DBFD0047EDD9
/* Align.swift in Sources */
,
96BCB7DC1CB40DC500C806FE
/* RaisedButton.swift in Sources */
,
96BCB7DD1CB40DC500C806FE
/* RobotoFont.swift in Sources */
,
96BCB7D71CB40DC500C806FE
/* MenuView.swift in Sources */
,
...
...
Sources/iOS/Align.swift
deleted
100644 → 0
View file @
531a6d39
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
public
class
Align
{
/// UIView context.
internal
weak
var
context
:
UIView
?
init
(
context
:
UIView
?)
{
self
.
context
=
context
}
/// Edges
public
func
edges
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParent
(
v
,
child
:
child
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
}
}
/// TopLeft
public
func
topLeft
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTopLeft
(
v
,
child
:
child
,
top
:
top
,
left
:
left
)
}
}
/// TopRight
public
func
topRight
(
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTopRight
(
v
,
child
:
child
,
top
:
top
,
right
:
right
)
}
}
/// BottomLeft
public
func
bottomLeft
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottomLeft
(
v
,
child
:
child
,
bottom
:
bottom
,
left
:
left
)
}
}
/// BottomRight
public
func
bottomRight
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottomRight
(
v
,
child
:
child
,
bottom
:
bottom
,
right
:
right
)
}
}
/// Top
public
func
top
(
child
:
UIView
,
top
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTop
(
v
,
child
:
child
,
top
:
top
)
}
}
/// Left
public
func
left
(
child
:
UIView
,
left
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromLeft
(
v
,
child
:
child
,
left
:
left
)
}
}
/// Bottom
public
func
bottom
(
child
:
UIView
,
bottom
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottom
(
v
,
child
:
child
,
bottom
:
bottom
)
}
}
/// Right
public
func
right
(
child
:
UIView
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromRight
(
v
,
child
:
child
,
right
:
right
)
}
}
/// Center
public
func
center
(
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
center
(
v
,
child
:
child
,
constantX
:
constantX
,
constantY
:
constantY
)
}
}
/// CenterHorizontally
public
func
centerHorizontally
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
centerHorizontally
(
v
,
child
:
child
,
constant
:
constant
)
}
}
/// CenterVertically
public
func
centerVertically
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
centerVertically
(
v
,
child
:
child
,
constant
:
constant
)
}
}
}
/// A memory reference to the AlignKey instance for UIView extensions.
private
var
AlignKey
:
UInt8
=
0
/// MaterialLayout extension for UIView.
public
extension
UIView
{
/// Align reference.
public
private(set)
var
align
:
Align
{
get
{
return
MaterialAssociatedObject
(
self
,
key
:
&
AlignKey
)
{
return
Align
(
context
:
self
)
}
}
set
(
value
)
{
MaterialAssociateObject
(
self
,
key
:
&
AlignKey
,
value
:
value
)
}
}
}
Sources/iOS/BottomTabBar.swift
View file @
e9be01ee
...
...
@@ -233,7 +233,7 @@ public class BottomTabBar : UITabBar {
super
.
didMoveToSuperview
()
if
autoLayoutToSuperview
{
if
let
v
:
UIView
=
superview
{
v
.
layout
.
align
FromB
ottom
(
self
)
v
.
layout
.
align
.
b
ottom
(
self
)
v
.
layout
.
horizontally
(
self
)
}
}
...
...
Sources/iOS/CardView.swift
View file @
e9be01ee
...
...
@@ -314,7 +314,7 @@ public class CardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
layout
.
align
FromB
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
layout
.
align
.
b
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
i
+=
1
}
...
...
@@ -343,7 +343,7 @@ public class CardView : MaterialPulseView {
h
+=
"-(right_left)-"
}
layout
.
align
FromB
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
layout
.
align
.
b
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
i
-=
1
}
...
...
Sources/iOS/ImageCardView.swift
View file @
e9be01ee
...
...
@@ -378,7 +378,7 @@ public class ImageCardView : MaterialPulseView {
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
}
else
{
layout
.
align
FromT
op
(
v
,
top
:
contentInset
.
top
+
titleLabelInset
.
top
)
layout
.
align
.
t
op
(
v
,
top
:
contentInset
.
top
+
titleLabelInset
.
top
)
}
layout
.
horizontally
(
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
...
...
@@ -417,7 +417,7 @@ public class ImageCardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
layout
.
align
FromB
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
layout
.
align
.
b
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
i
+=
1
}
...
...
@@ -446,7 +446,7 @@ public class ImageCardView : MaterialPulseView {
h
+=
"-(right_left)-"
}
layout
.
align
FromB
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
layout
.
align
.
b
ottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
i
-=
1
}
...
...
Sources/iOS/Layout.swift
View file @
e9be01ee
...
...
@@ -30,144 +30,320 @@
import
UIKit
public
class
Layout
{
public
class
Align
{
/// UIView context.
internal
weak
var
context
:
UIView
?
init
(
context
:
UIView
?)
{
self
.
context
=
context
}
///
Width
public
func
width
(
child
:
UIView
,
width
:
CGFloat
=
0
)
{
///
Edges
public
func
edges
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
width
(
v
,
child
:
child
,
width
:
width
)
Layout
.
alignToParent
(
v
,
child
:
child
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
}
}
///
Heigh
t
public
func
height
(
child
:
UIView
,
heigh
t
:
CGFloat
=
0
)
{
///
TopLef
t
public
func
topLeft
(
child
:
UIView
,
top
:
CGFloat
=
0
,
lef
t
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
height
(
v
,
child
:
child
,
height
:
heigh
t
)
Layout
.
alignFromTopLeft
(
v
,
child
:
child
,
top
:
top
,
left
:
lef
t
)
}
}
///
Size
public
func
size
(
child
:
UIView
,
width
:
CGFloat
=
0
,
he
ight
:
CGFloat
=
0
)
{
///
TopRight
public
func
topRight
(
child
:
UIView
,
top
:
CGFloat
=
0
,
r
ight
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
size
(
v
,
child
:
child
,
width
:
width
,
height
:
he
ight
)
Layout
.
alignFromTopRight
(
v
,
child
:
child
,
top
:
top
,
right
:
r
ight
)
}
}
///
Array of UIViews horizontally aligned.
public
func
horizontally
(
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
///
BottomLeft
public
func
bottomLeft
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParentHorizontally
(
v
,
children
:
children
,
left
:
left
,
right
:
right
,
spacing
:
spacing
)
Layout
.
alignFromBottomLeft
(
v
,
child
:
child
,
bottom
:
bottom
,
left
:
left
)
}
}
///
Array of UIViews vertically aligned.
public
func
vertically
(
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
///
BottomRight
public
func
bottomRight
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParentVertically
(
v
,
children
:
children
,
top
:
top
,
bottom
:
bottom
,
spacing
:
spacing
)
Layout
.
alignFromBottomRight
(
v
,
child
:
child
,
bottom
:
bottom
,
right
:
right
)
}
}
///
Horizontally aligned.
public
func
horizontally
(
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
///
Top
public
func
top
(
child
:
UIView
,
top
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParentHorizontally
(
v
,
child
:
child
,
left
:
left
,
right
:
right
)
Layout
.
alignFromTop
(
v
,
child
:
child
,
top
:
top
)
}
}
///
Vertically aligned.
public
func
vertically
(
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
{
///
Left
public
func
left
(
child
:
UIView
,
left
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParentVertically
(
v
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
Layout
.
alignFromLeft
(
v
,
child
:
child
,
left
:
left
)
}
}
///
Layout
public
func
align
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
///
Bottom
public
func
bottom
(
child
:
UIView
,
bottom
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignToParent
(
v
,
child
:
child
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
Layout
.
alignFromBottom
(
v
,
child
:
child
,
bottom
:
bottom
)
}
}
///
LayoutFromTopLef
t
public
func
alignFromTopLeft
(
child
:
UIView
,
top
:
CGFloat
=
0
,
lef
t
:
CGFloat
=
0
)
{
///
Righ
t
public
func
right
(
child
:
UIView
,
righ
t
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTopLeft
(
v
,
child
:
child
,
top
:
top
,
left
:
lef
t
)
Layout
.
alignFromRight
(
v
,
child
:
child
,
right
:
righ
t
)
}
}
}
public
class
Layout
{
/// Reference to Align.
public
private(set)
var
align
:
Align
/// UIView context.
internal
weak
var
context
:
UIView
?
/// LayoutFromTopRight
public
func
alignFromTopRight
(
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
init
(
context
:
UIView
?)
{
self
.
context
=
context
self
.
align
=
Align
(
context
:
context
)
}
/// Width
public
func
width
(
child
:
UIView
,
width
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTopRight
(
v
,
child
:
child
,
top
:
top
,
right
:
right
)
Layout
.
width
(
v
,
child
:
child
,
width
:
width
)
}
}
///
LayoutFromBottomLef
t
public
func
alignFromBottomLeft
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
lef
t
:
CGFloat
=
0
)
{
///
Heigh
t
public
func
height
(
child
:
UIView
,
heigh
t
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottomLeft
(
v
,
child
:
child
,
bottom
:
bottom
,
left
:
lef
t
)
Layout
.
height
(
v
,
child
:
child
,
height
:
heigh
t
)
}
}
///
LayoutFromBottomRight
public
func
alignFromBottomRight
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
r
ight
:
CGFloat
=
0
)
{
///
Size
public
func
size
(
child
:
UIView
,
width
:
CGFloat
=
0
,
he
ight
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottomRight
(
v
,
child
:
child
,
bottom
:
bottom
,
right
:
r
ight
)
Layout
.
size
(
v
,
child
:
child
,
width
:
width
,
height
:
he
ight
)
}
}
///
LayoutFromTop
public
func
alignFromTop
(
child
:
UIView
,
top
:
CGFloat
=
0
)
{
///
Array of UIViews horizontally aligned.
public
func
horizontally
(
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromTop
(
v
,
child
:
child
,
top
:
top
)
Layout
.
alignToParentHorizontally
(
v
,
children
:
children
,
left
:
left
,
right
:
right
,
spacing
:
spacing
)
}
}
///
LayoutFromLeft
public
func
alignFromLeft
(
child
:
UIView
,
left
:
CGFloat
=
0
)
{
///
Array of UIViews vertically aligned.
public
func
vertically
(
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromLeft
(
v
,
child
:
child
,
left
:
left
)
Layout
.
alignToParentVertically
(
v
,
children
:
children
,
top
:
top
,
bottom
:
bottom
,
spacing
:
spacing
)
}
}
///
LayoutFromBottom
public
func
alignFromBottom
(
child
:
UIView
,
bottom
:
CGFloat
=
0
)
{
///
Horizontally aligned.
public
func
horizontally
(
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromBottom
(
v
,
child
:
child
,
bottom
:
bottom
)
Layout
.
alignToParentHorizontally
(
v
,
child
:
child
,
left
:
left
,
right
:
right
)
}
}
///
LayoutFromRight
public
func
alignFromRight
(
child
:
UIView
,
right
:
CGFloat
=
0
)
{
///
Vertically aligned.
public
func
vertically
(
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
alignFromRight
(
v
,
child
:
child
,
right
:
right
)
Layout
.
alignToParentVertically
(
v
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
}
}
/// Center
public
func
center
(
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
Material
Layout
.
center
(
v
,
child
:
child
,
constantX
:
constantX
,
constantY
:
constantY
)
Layout
.
center
(
v
,
child
:
child
,
constantX
:
constantX
,
constantY
:
constantY
)
}
}
/// CenterHorizontally
public
func
centerHorizontally
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
Material
Layout
.
centerHorizontally
(
v
,
child
:
child
,
constant
:
constant
)
Layout
.
centerHorizontally
(
v
,
child
:
child
,
constant
:
constant
)
}
}
/// CenterVertically
public
func
centerVertically
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
if
let
v
:
UIView
=
context
{
MaterialLayout
.
centerVertically
(
v
,
child
:
child
,
constant
:
constant
)
Layout
.
centerVertically
(
v
,
child
:
child
,
constant
:
constant
)
}
}
}
/// Layout
public
extension
Layout
{
/// Width
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
))
}
/// Height
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
))
}
/// Size
public
class
func
size
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
height
:
CGFloat
=
0
)
{
Layout
.
width
(
parent
,
child
:
child
,
width
:
width
)
Layout
.
height
(
parent
,
child
:
child
,
height
:
height
)
}
/// AlignToParentHorizontally
public
class
func
alignToParentHorizontally
(
parent
:
UIView
,
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
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
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Left
,
relatedBy
:
.
Equal
,
toItem
:
children
[
i
-
1
],
attribute
:
.
Right
,
multiplier
:
1
,
constant
:
spacing
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Width
,
relatedBy
:
.
Equal
,
toItem
:
children
[
0
],
attribute
:
.
Width
,
multiplier
:
1
,
constant
:
0
))
}
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
children
.
count
-
1
],
attribute
:
.
Right
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Right
,
multiplier
:
1
,
constant
:
-
right
))
}
}
/// AlignToParentVertically
public
class
func
alignToParentVertically
(
parent
:
UIView
,
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
children
:
children
)
if
0
<
children
.
count
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
0
],
attribute
:
.
Top
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Top
,
multiplier
:
1
,
constant
:
top
))
for
i
in
1
..<
children
.
count
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Top
,
relatedBy
:
.
Equal
,
toItem
:
children
[
i
-
1
],
attribute
:
.
Bottom
,
multiplier
:
1
,
constant
:
spacing
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Height
,
relatedBy
:
.
Equal
,
toItem
:
children
[
0
],
attribute
:
.
Height
,
multiplier
:
1
,
constant
:
0
))
}
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
children
.
count
-
1
],
attribute
:
.
Bottom
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Bottom
,
multiplier
:
1
,
constant
:
-
bottom
))
}
}
/// AlignToParentHorizontally
public
class
func
alignToParentHorizontally
(
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
))
}
/// AlignToParentVertically
public
class
func
alignToParentVertically
(
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
))
}
/// AlignToParent
public
class
func
alignToParent
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignToParentHorizontally
(
parent
,
child
:
child
,
left
:
left
,
right
:
right
)
alignToParentVertically
(
parent
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
}
/// AlignFromTopLeft
public
class
func
alignFromTopLeft
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
/// AlignFromTopRight
public
class
func
alignFromTopRight
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
/// AlignFromBottomLeft
public
class
func
alignFromBottomLeft
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
/// AlignFromBottomRight
public
class
func
alignFromBottomRight
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
/// AlignFromTop
public
class
func
alignFromTop
(
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
))
}
/// AlignFromLeft
public
class
func
alignFromLeft
(
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
))
}
/// AlignFromBottom
public
class
func
alignFromBottom
(
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
))
}
/// AlignFromRight
public
class
func
alignFromRight
(
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
))
}
/// Center
public
class
func
center
(
parent
:
UIView
,
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
{
centerHorizontally
(
parent
,
child
:
child
,
constant
:
constantX
)
centerVertically
(
parent
,
child
:
child
,
constant
:
constantY
)
}
/// CenterHorizontally
public
class
func
centerHorizontally
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterX
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterX
,
multiplier
:
1
,
constant
:
constant
))
}
/// CenterVertically
public
class
func
centerVertically
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterY
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterY
,
multiplier
:
1
,
constant
:
constant
))
}
/// Constraint
public
class
func
constraint
(
format
:
String
,
options
:
NSLayoutFormatOptions
,
metrics
:
Dictionary
<
String
,
AnyObject
>
?,
views
:
Dictionary
<
String
,
AnyObject
>
)
->
Array
<
NSLayoutConstraint
>
{
for
(
_
,
a
)
in
views
{
if
let
v
:
UIView
=
a
as?
UIView
{
v
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
return
NSLayoutConstraint
.
constraintsWithVisualFormat
(
format
,
options
:
options
,
metrics
:
metrics
,
views
:
views
)
}
/// prepareForConstraint
private
class
func
prepareForConstraint
(
parent
:
UIView
,
child
:
UIView
)
{
if
parent
!=
child
.
superview
{
parent
.
addSubview
(
child
)
}
child
.
translatesAutoresizingMaskIntoConstraints
=
false
}
/// prepareForConstraint
private
class
func
prepareForConstraint
(
parent
:
UIView
,
children
:
[
UIView
])
{
for
v
in
children
{
prepareForConstraint
(
parent
,
child
:
v
)
}
}
}
...
...
@@ -175,7 +351,7 @@ public class Layout {
/// A memory reference to the LayoutKey instance for UIView extensions.
private
var
LayoutKey
:
UInt8
=
0
///
Material
Layout extension for UIView.
/// Layout extension for UIView.
public
extension
UIView
{
/// Layout reference.
public
private(set)
var
layout
:
Layout
{
...
...
Sources/iOS/MaterialLayout.swift
deleted
100644 → 0
View file @
531a6d39
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import
UIKit
/// MaterialLayout
public
struct
MaterialLayout
{
/// Width
public
static
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
))
}
/// Height
public
static
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
))
}
/// Size
public
static
func
size
(
parent
:
UIView
,
child
:
UIView
,
width
:
CGFloat
=
0
,
height
:
CGFloat
=
0
)
{
MaterialLayout
.
width
(
parent
,
child
:
child
,
width
:
width
)
MaterialLayout
.
height
(
parent
,
child
:
child
,
height
:
height
)
}
/// AlignToParentHorizontally
public
static
func
alignToParentHorizontally
(
parent
:
UIView
,
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
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
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Left
,
relatedBy
:
.
Equal
,
toItem
:
children
[
i
-
1
],
attribute
:
.
Right
,
multiplier
:
1
,
constant
:
spacing
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Width
,
relatedBy
:
.
Equal
,
toItem
:
children
[
0
],
attribute
:
.
Width
,
multiplier
:
1
,
constant
:
0
))
}
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
children
.
count
-
1
],
attribute
:
.
Right
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Right
,
multiplier
:
1
,
constant
:
-
right
))
}
}
/// AlignToParentVertically
public
static
func
alignToParentVertically
(
parent
:
UIView
,
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
children
:
children
)
if
0
<
children
.
count
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
0
],
attribute
:
.
Top
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Top
,
multiplier
:
1
,
constant
:
top
))
for
i
in
1
..<
children
.
count
{
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Top
,
relatedBy
:
.
Equal
,
toItem
:
children
[
i
-
1
],
attribute
:
.
Bottom
,
multiplier
:
1
,
constant
:
spacing
))
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
i
],
attribute
:
.
Height
,
relatedBy
:
.
Equal
,
toItem
:
children
[
0
],
attribute
:
.
Height
,
multiplier
:
1
,
constant
:
0
))
}
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
children
[
children
.
count
-
1
],
attribute
:
.
Bottom
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Bottom
,
multiplier
:
1
,
constant
:
-
bottom
))
}
}
/// AlignToParentHorizontally
public
static
func
alignToParentHorizontally
(
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
))
}
/// AlignToParentVertically
public
static
func
alignToParentVertically
(
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
))
}
/// AlignToParent
public
static
func
alignToParent
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignToParentHorizontally
(
parent
,
child
:
child
,
left
:
left
,
right
:
right
)
alignToParentVertically
(
parent
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
}
/// AlignFromTopLeft
public
static
func
alignFromTopLeft
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
/// AlignFromTopRight
public
static
func
alignFromTopRight
(
parent
:
UIView
,
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignFromTop
(
parent
,
child
:
child
,
top
:
top
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
/// AlignFromBottomLeft
public
static
func
alignFromBottomLeft
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromLeft
(
parent
,
child
:
child
,
left
:
left
)
}
/// AlignFromBottomRight
public
static
func
alignFromBottomRight
(
parent
:
UIView
,
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
alignFromBottom
(
parent
,
child
:
child
,
bottom
:
bottom
)
alignFromRight
(
parent
,
child
:
child
,
right
:
right
)
}
/// AlignFromTop
public
static
func
alignFromTop
(
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
))
}
/// AlignFromLeft
public
static
func
alignFromLeft
(
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
))
}
/// AlignFromBottom
public
static
func
alignFromBottom
(
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
))
}
/// AlignFromRight
public
static
func
alignFromRight
(
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
))
}
/// Center
public
static
func
center
(
parent
:
UIView
,
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
{
centerHorizontally
(
parent
,
child
:
child
,
constant
:
constantX
)
centerVertically
(
parent
,
child
:
child
,
constant
:
constantY
)
}
/// CenterHorizontally
public
static
func
centerHorizontally
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterX
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterX
,
multiplier
:
1
,
constant
:
constant
))
}
/// CenterVertically
public
static
func
centerVertically
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
(
parent
,
child
:
child
)
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterY
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterY
,
multiplier
:
1
,
constant
:
constant
))
}
/// Constraint
public
static
func
constraint
(
format
:
String
,
options
:
NSLayoutFormatOptions
,
metrics
:
Dictionary
<
String
,
AnyObject
>
?,
views
:
Dictionary
<
String
,
AnyObject
>
)
->
Array
<
NSLayoutConstraint
>
{
for
(
_
,
a
)
in
views
{
if
let
v
:
UIView
=
a
as?
UIView
{
v
.
translatesAutoresizingMaskIntoConstraints
=
false
}
}
return
NSLayoutConstraint
.
constraintsWithVisualFormat
(
format
,
options
:
options
,
metrics
:
metrics
,
views
:
views
)
}
/// prepareForConstraint
private
static
func
prepareForConstraint
(
parent
:
UIView
,
child
:
UIView
)
{
if
parent
!=
child
.
superview
{
parent
.
addSubview
(
child
)
}
child
.
translatesAutoresizingMaskIntoConstraints
=
false
}
/// prepareForConstraint
private
static
func
prepareForConstraint
(
parent
:
UIView
,
children
:
[
UIView
])
{
for
v
in
children
{
prepareForConstraint
(
parent
,
child
:
v
)
}
}
}
Sources/iOS/TextView.swift
View file @
e9be01ee
...
...
@@ -401,7 +401,7 @@ public class TextView: UITextView {
internal
func
reloadView
()
{
if
let
p
=
placeholderLabel
{
removeConstraints
(
constraints
)
layout
.
align
(
p
,
layout
.
align
.
edges
(
p
,
top
:
textContainerInset
.
top
,
left
:
textContainerInset
.
left
+
textContainer
.
lineFragmentPadding
,
bottom
:
textContainerInset
.
bottom
,
...
...
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