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
d52bee10
Commit
d52bee10
authored
Jun 10, 2016
by
Daniel Dahan
Committed by
GitHub
Jun 10, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #437 from mohpor/development
New Layout API added to Material and Example Projects
parents
2b3fa494
2a14b2cc
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
421 additions
and
142 deletions
+421
-142
Examples/Programmatic/App/App/AppLeftViewController.swift
+3
-10
Examples/Programmatic/App/App/AppMenuController.swift
+2
-2
Examples/Programmatic/App/App/ItemViewController.swift
+1
-1
Examples/Programmatic/App/App/RecipesViewController.swift
+2
-2
Examples/Programmatic/App/App/RecommendationViewController.swift
+2
-2
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+1
-1
Examples/Programmatic/CardView/CardView/ViewController.swift
+4
-8
Examples/Programmatic/ImageCardView/ImageCardView/ViewController.swift
+2
-4
Examples/Programmatic/Layout/Layout/ViewController.swift
+6
-11
Examples/Programmatic/MaterialCollectionView/MaterialCollectionView/ViewController.swift
+1
-1
Examples/Programmatic/MaterialDepth/MaterialDepth/ViewController.swift
+1
-1
Examples/Programmatic/MaterialIcon/MaterialIcon/ViewController.swift
+1
-1
Examples/Programmatic/MenuController/MenuController/AppMenuController.swift
+2
-3
Examples/Programmatic/MenuView/MenuView/ViewController.swift
+1
-2
Examples/Programmatic/SearchBar/SearchBar/ViewController.swift
+1
-1
Examples/Programmatic/SideNavigationController/SideNavigationController/AppLeftViewController.swift
+1
-1
Examples/Programmatic/TableCardView/TableCardView/ViewController.swift
+1
-1
Examples/Programmatic/TextField/TextField/ViewController.swift
+3
-6
Examples/Programmatic/TextView/TextView/ViewController.swift
+1
-1
Examples/Programmatic/Toolbar/Toolbar/ViewController.swift
+1
-1
Examples/Storyboards/SideNavigationController/SideNavigationController/MainViewController.swift
+1
-2
Sources/iOS/BottomTabBar.swift
+2
-2
Sources/iOS/CardView.swift
+4
-4
Sources/iOS/ImageCardView.swift
+5
-5
Sources/iOS/Layout.swift
+371
-68
Sources/iOS/TextView.swift
+1
-1
No files found.
Examples/Programmatic/App/App/AppLeftViewController.swift
View file @
d52bee10
...
@@ -96,15 +96,8 @@ class AppLeftViewController: UIViewController {
...
@@ -96,15 +96,8 @@ class AppLeftViewController: UIViewController {
nameLabel
.
textColor
=
MaterialColor
.
white
nameLabel
.
textColor
=
MaterialColor
.
white
nameLabel
.
font
=
RobotoFont
.
mediumWithSize
(
18
)
nameLabel
.
font
=
RobotoFont
.
mediumWithSize
(
18
)
view
.
layout
.
size
(
profileView
,
width
:
72
,
height
:
72
)
view
.
layout
(
profileView
)
.
width
(
72
)
.
height
(
72
)
.
top
(
30
)
.
centerHorizontally
()
view
.
layout
.
align
.
topLeft
(
profileView
,
top
:
30
,
left
:
(
view
.
bounds
.
width
-
72
)
/
2
)
view
.
layout
(
nameLabel
)
.
top
(
130
)
.
left
(
20
)
.
right
(
20
)
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)
// view.layout.horizontally(nameLabel, left: 20, right: 20)
}
}
/// Prepares the tableView.
/// Prepares the tableView.
...
@@ -116,7 +109,7 @@ class AppLeftViewController: UIViewController {
...
@@ -116,7 +109,7 @@ class AppLeftViewController: UIViewController {
tableView
.
separatorStyle
=
.
None
tableView
.
separatorStyle
=
.
None
// Use Layout to easily align the tableView.
// Use Layout to easily align the tableView.
view
.
layout
.
align
.
edges
(
tableView
,
top
:
170
)
view
.
layout
(
tableView
)
.
edges
(
top
:
170
)
}
}
}
}
...
...
Examples/Programmatic/App/App/AppMenuController.swift
View file @
d52bee10
...
@@ -156,8 +156,8 @@ class AppMenuController: MenuController {
...
@@ -156,8 +156,8 @@ class AppMenuController: MenuController {
menuView
.
menu
.
views
=
[
menuButton
,
blueButton
,
greenButton
,
yellowButton
]
menuView
.
menu
.
views
=
[
menuButton
,
blueButton
,
greenButton
,
yellowButton
]
menuView
.
delegate
=
self
menuView
.
delegate
=
self
view
.
layout
.
size
(
menuView
,
width
:
baseSize
.
width
,
height
:
baseSize
.
heigh
t
)
view
.
layout
(
menuView
)
.
width
(
baseSize
.
width
)
.
height
(
baseSize
.
height
)
.
bottom
(
menuViewInset
)
.
right
(
menuViewInse
t
)
view
.
layout
.
align
.
bottomRight
(
menuView
,
bottom
:
menuViewInset
,
right
:
menuViewInset
)
}
}
/// Prepare tabBarItem.
/// Prepare tabBarItem.
...
...
Examples/Programmatic/App/App/ItemViewController.swift
View file @
d52bee10
...
@@ -82,7 +82,7 @@ class ItemViewController: UIViewController {
...
@@ -82,7 +82,7 @@ class ItemViewController: UIViewController {
scrollView
.
frame
=
view
.
bounds
scrollView
.
frame
=
view
.
bounds
scrollView
.
removeConstraints
(
scrollView
.
constraints
)
scrollView
.
removeConstraints
(
scrollView
.
constraints
)
scrollView
.
layout
.
width
(
imageCardView
,
width
:
scrollView
.
bounds
.
width
)
scrollView
.
layout
(
imageCardView
)
.
width
(
scrollView
.
bounds
.
width
)
imageCardView
.
layoutIfNeeded
()
imageCardView
.
layoutIfNeeded
()
scrollView
.
contentSize
=
CGSizeMake
(
view
.
bounds
.
width
,
imageCardView
.
height
)
scrollView
.
contentSize
=
CGSizeMake
(
view
.
bounds
.
width
,
imageCardView
.
height
)
...
...
Examples/Programmatic/App/App/RecipesViewController.swift
View file @
d52bee10
...
@@ -169,7 +169,7 @@ class RecipesViewController: UIViewController {
...
@@ -169,7 +169,7 @@ class RecipesViewController: UIViewController {
tableView
.
delegate
=
self
tableView
.
delegate
=
self
// Use Layout to easily align the tableView.
// Use Layout to easily align the tableView.
view
.
layout
.
align
.
edges
(
tableView
)
view
.
layout
(
tableView
)
.
edges
(
)
}
}
}
}
...
@@ -214,7 +214,7 @@ extension RecipesViewController: UITableViewDataSource {
...
@@ -214,7 +214,7 @@ extension RecipesViewController: UITableViewDataSource {
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
text
=
"Favorites"
label
.
text
=
"Favorites"
header
.
layout
.
align
.
edges
(
label
,
left
:
24
)
header
.
layout
(
label
)
.
edges
(
left
:
24
)
return
header
return
header
}
}
...
...
Examples/Programmatic/App/App/RecommendationViewController.swift
View file @
d52bee10
...
@@ -70,7 +70,7 @@ class RecommendationViewController: UIViewController {
...
@@ -70,7 +70,7 @@ class RecommendationViewController: UIViewController {
tableView
.
delegate
=
self
tableView
.
delegate
=
self
// Use Layout to easily align the tableView.
// Use Layout to easily align the tableView.
view
.
layout
.
align
.
edges
(
tableView
)
view
.
layout
(
tableView
)
.
edges
(
)
}
}
}
}
...
@@ -115,7 +115,7 @@ extension RecommendationViewController: UITableViewDataSource {
...
@@ -115,7 +115,7 @@ extension RecommendationViewController: UITableViewDataSource {
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
textColor
=
MaterialColor
.
grey
.
darken1
label
.
text
=
"Recommendations"
label
.
text
=
"Recommendations"
header
.
layout
.
align
.
edges
(
label
,
left
:
24
)
header
.
layout
(
label
)
.
edges
(
left
:
24
)
return
header
return
header
}
}
...
...
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
d52bee10
...
@@ -226,7 +226,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
...
@@ -226,7 +226,7 @@ class ViewController: UIViewController, CaptureViewDelegate, CaptureSessionDeleg
captureView
.
tapToExposeEnabled
=
true
captureView
.
tapToExposeEnabled
=
true
captureView
.
delegate
=
self
captureView
.
delegate
=
self
captureView
.
captureSession
.
delegate
=
self
captureView
.
captureSession
.
delegate
=
self
view
.
layout
.
align
(
captureView
)
view
.
layout
(
captureView
)
.
edges
(
)
}
}
/**
/**
...
...
Examples/Programmatic/CardView/CardView/ViewController.swift
View file @
d52bee10
...
@@ -79,8 +79,7 @@ class ViewController: UIViewController {
...
@@ -79,8 +79,7 @@ class ViewController: UIViewController {
cardView
.
leftButtons
=
[
btn1
,
btn2
]
cardView
.
leftButtons
=
[
btn1
,
btn2
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
cardView
,
top
:
100
)
view
.
layout
(
cardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
cardView
,
left
:
20
,
right
:
20
)
}
}
private
func
prepareCardViewWithoutPulseBackgroundImageExample
()
{
private
func
prepareCardViewWithoutPulseBackgroundImageExample
()
{
...
@@ -117,8 +116,7 @@ class ViewController: UIViewController {
...
@@ -117,8 +116,7 @@ class ViewController: UIViewController {
cardView
.
leftButtons
=
[
btn1
]
cardView
.
leftButtons
=
[
btn1
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
cardView
,
top
:
100
)
view
.
layout
(
cardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
cardView
,
left
:
20
,
right
:
20
)
}
}
private
func
prepareCardViewWithPulseBackgroundImageExample
()
{
private
func
prepareCardViewWithPulseBackgroundImageExample
()
{
...
@@ -156,8 +154,7 @@ class ViewController: UIViewController {
...
@@ -156,8 +154,7 @@ class ViewController: UIViewController {
cardView
.
leftButtons
=
[
btn1
]
cardView
.
leftButtons
=
[
btn1
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
cardView
,
top
:
100
)
view
.
layout
(
cardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
cardView
,
left
:
20
,
right
:
20
)
}
}
private
func
prepareCardViewButtonBarExample
()
{
private
func
prepareCardViewButtonBarExample
()
{
...
@@ -194,8 +191,7 @@ class ViewController: UIViewController {
...
@@ -194,8 +191,7 @@ class ViewController: UIViewController {
cardView
.
rightButtons
=
[
btn2
,
btn3
]
cardView
.
rightButtons
=
[
btn2
,
btn3
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
cardView
,
top
:
100
)
view
.
layout
(
cardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
cardView
,
left
:
20
,
right
:
20
)
}
}
}
}
Examples/Programmatic/ImageCardView/ImageCardView/ViewController.swift
View file @
d52bee10
...
@@ -83,8 +83,7 @@ class ViewController: UIViewController {
...
@@ -83,8 +83,7 @@ class ViewController: UIViewController {
imageCardView
.
leftButtons
=
[
btn1
,
btn2
]
imageCardView
.
leftButtons
=
[
btn1
,
btn2
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
imageCardView
,
top
:
100
)
view
.
layout
(
imageCardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
imageCardView
,
left
:
20
,
right
:
20
)
}
}
private
func
prepareImageCardViewWithoutDetailLabelAndDividerExample
()
{
private
func
prepareImageCardViewWithoutDetailLabelAndDividerExample
()
{
...
@@ -132,8 +131,7 @@ class ViewController: UIViewController {
...
@@ -132,8 +131,7 @@ class ViewController: UIViewController {
imageCardView
.
rightButtons
=
[
btn1
,
btn2
,
btn3
]
imageCardView
.
rightButtons
=
[
btn1
,
btn2
,
btn3
]
// To support orientation changes, use Layout.
// To support orientation changes, use Layout.
view
.
layout
.
alignFromTop
(
imageCardView
,
top
:
100
)
view
.
layout
(
imageCardView
)
.
top
(
100
)
.
left
(
20
)
.
right
(
20
)
view
.
layout
.
horizontally
(
imageCardView
,
left
:
20
,
right
:
20
)
}
}
}
}
Examples/Programmatic/Layout/Layout/ViewController.swift
View file @
d52bee10
...
@@ -41,7 +41,7 @@ class ViewController: UIViewController {
...
@@ -41,7 +41,7 @@ class ViewController: UIViewController {
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareView
()
//
prepareAlignToParentHorizontallyAndVerticallyExample()
prepareAlignToParentHorizontallyAndVerticallyExample
()
prepareCenterExample
()
prepareCenterExample
()
}
}
...
@@ -74,11 +74,9 @@ class ViewController: UIViewController {
...
@@ -74,11 +74,9 @@ class ViewController: UIViewController {
let
children
:
Array
<
UIView
>
=
[
label1
,
label2
,
label3
,
label4
]
let
children
:
Array
<
UIView
>
=
[
label1
,
label2
,
label3
,
label4
]
// Align the labels vertically with an equal height.
// Align the labels
horizontally with an equal width and
vertically with an equal height.
view
.
layout
.
vertically
(
children
,
top
:
100
,
bottom
:
100
)
view
.
layout
.
horizontally
(
children
,
left
:
30
,
right
:
30
,
spacing
:
30
)
.
vertically
(
children
,
top
:
100
,
bottom
:
100
)
// Align the labels horizontally with an equal width.
view
.
layout
.
horizontally
(
children
,
left
:
30
,
right
:
30
,
spacing
:
30
)
// Print out the dimensions of the labels.
// Print out the dimensions of the labels.
for
v
in
children
{
for
v
in
children
{
...
@@ -98,8 +96,7 @@ class ViewController: UIViewController {
...
@@ -98,8 +96,7 @@ class ViewController: UIViewController {
labelCX
.
layer
.
cornerRadius
=
length
/
2.0
labelCX
.
layer
.
cornerRadius
=
length
/
2.0
labelCX
.
clipsToBounds
=
true
labelCX
.
clipsToBounds
=
true
view
.
layout
.
size
(
labelCX
,
width
:
length
,
height
:
length
)
view
.
layout
(
labelCX
)
.
width
(
length
)
.
height
(
length
)
.
centerHorizontally
()
view
.
layout
.
centerHorizontally
(
labelCX
)
let
labelCY
=
UILabel
()
let
labelCY
=
UILabel
()
labelCY
.
backgroundColor
=
MaterialColor
.
grey
.
base
labelCY
.
backgroundColor
=
MaterialColor
.
grey
.
base
...
@@ -108,8 +105,7 @@ class ViewController: UIViewController {
...
@@ -108,8 +105,7 @@ class ViewController: UIViewController {
labelCY
.
layer
.
cornerRadius
=
length
/
2.0
labelCY
.
layer
.
cornerRadius
=
length
/
2.0
labelCY
.
clipsToBounds
=
true
labelCY
.
clipsToBounds
=
true
view
.
layout
.
size
(
labelCY
,
width
:
length
,
height
:
length
)
view
.
layout
(
labelCY
)
.
width
(
length
)
.
height
(
length
)
.
centerVertically
()
view
.
layout
.
centerVertically
(
labelCY
)
let
labelCXY
=
UILabel
()
let
labelCXY
=
UILabel
()
labelCXY
.
backgroundColor
=
MaterialColor
.
grey
.
base
labelCXY
.
backgroundColor
=
MaterialColor
.
grey
.
base
...
@@ -118,8 +114,7 @@ class ViewController: UIViewController {
...
@@ -118,8 +114,7 @@ class ViewController: UIViewController {
labelCXY
.
layer
.
cornerRadius
=
length
/
2.0
labelCXY
.
layer
.
cornerRadius
=
length
/
2.0
labelCXY
.
clipsToBounds
=
true
labelCXY
.
clipsToBounds
=
true
view
.
layout
.
size
(
labelCXY
,
width
:
length
,
height
:
length
)
view
.
layout
(
labelCXY
)
.
width
(
length
)
.
height
(
length
)
.
center
()
view
.
layout
.
center
(
labelCXY
)
}
}
}
}
Examples/Programmatic/MaterialCollectionView/MaterialCollectionView/ViewController.swift
View file @
d52bee10
...
@@ -85,7 +85,7 @@ class ViewController: UIViewController {
...
@@ -85,7 +85,7 @@ class ViewController: UIViewController {
collectionView
.
contentInset
.
top
=
100
collectionView
.
contentInset
.
top
=
100
collectionView
.
spacing
=
16
collectionView
.
spacing
=
16
view
.
layout
.
align
(
collectionView
)
view
.
layout
(
collectionView
)
.
edges
(
)
}
}
}
}
...
...
Examples/Programmatic/MaterialDepth/MaterialDepth/ViewController.swift
View file @
d52bee10
...
@@ -70,7 +70,7 @@ class ViewController: UIViewController {
...
@@ -70,7 +70,7 @@ class ViewController: UIViewController {
If this is left out, the intrinsic value is used for the view.
If this is left out, the intrinsic value is used for the view.
*/
*/
for
v
in
children
{
for
v
in
children
{
view
.
layout
.
horizontally
(
v
,
left
:
20
,
right
:
20
)
view
.
layout
(
v
)
.
horizontally
(
left
:
20
,
right
:
20
)
}
}
}
}
}
}
...
...
Examples/Programmatic/MaterialIcon/MaterialIcon/ViewController.swift
View file @
d52bee10
...
@@ -109,11 +109,11 @@ class ViewController: UIViewController {
...
@@ -109,11 +109,11 @@ class ViewController: UIViewController {
/// Prepares the tableView.
/// Prepares the tableView.
private
func
prepareTableView
()
{
private
func
prepareTableView
()
{
view
.
layout
(
tableView
)
.
edges
(
top
:
20
)
tableView
.
registerClass
(
MaterialTableViewCell
.
self
,
forCellReuseIdentifier
:
"Cell"
)
tableView
.
registerClass
(
MaterialTableViewCell
.
self
,
forCellReuseIdentifier
:
"Cell"
)
tableView
.
dataSource
=
self
tableView
.
dataSource
=
self
tableView
.
delegate
=
self
tableView
.
delegate
=
self
view
.
layout
.
align
(
tableView
,
top
:
20
)
}
}
private
func
image
(
iconName
:
String
!
)
->
UIImage
?
{
private
func
image
(
iconName
:
String
!
)
->
UIImage
?
{
...
...
Examples/Programmatic/MenuController/MenuController/AppMenuController.swift
View file @
d52bee10
...
@@ -105,7 +105,7 @@ class AppMenuController: MenuController {
...
@@ -105,7 +105,7 @@ class AppMenuController: MenuController {
view
.
backgroundColor
=
MaterialColor
.
black
view
.
backgroundColor
=
MaterialColor
.
black
prepareMenuView
()
prepareMenuView
()
}
}
/// Prepares the add button.
/// Prepares the add button.
private
func
prepareMenuView
()
{
private
func
prepareMenuView
()
{
var
image
:
UIImage
?
=
MaterialIcon
.
cm
.
add
var
image
:
UIImage
?
=
MaterialIcon
.
cm
.
add
...
@@ -148,8 +148,7 @@ class AppMenuController: MenuController {
...
@@ -148,8 +148,7 @@ class AppMenuController: MenuController {
menuView
.
menu
.
views
=
[
menuButton
,
blueButton
,
greenButton
,
yellowButton
]
menuView
.
menu
.
views
=
[
menuButton
,
blueButton
,
greenButton
,
yellowButton
]
menuView
.
delegate
=
self
menuView
.
delegate
=
self
view
.
layout
.
size
(
menuView
,
width
:
baseSize
.
width
,
height
:
baseSize
.
height
)
view
.
layout
(
menuView
)
.
width
(
baseSize
.
width
)
.
height
(
baseSize
.
height
)
.
bottom
(
menuViewInset
)
.
right
(
menuViewInset
)
view
.
layout
.
alignFromBottomRight
(
menuView
,
bottom
:
menuViewInset
,
right
:
menuViewInset
)
}
}
}
}
...
...
Examples/Programmatic/MenuView/MenuView/ViewController.swift
View file @
d52bee10
...
@@ -137,8 +137,7 @@ class ViewController: UIViewController {
...
@@ -137,8 +137,7 @@ class ViewController: UIViewController {
menuView
.
menu
.
baseSize
=
CGSizeMake
(
diameter
,
diameter
)
menuView
.
menu
.
baseSize
=
CGSizeMake
(
diameter
,
diameter
)
menuView
.
menu
.
views
=
[
btn1
,
btn2
,
btn3
,
btn4
]
menuView
.
menu
.
views
=
[
btn1
,
btn2
,
btn3
,
btn4
]
view
.
layout
.
size
(
menuView
,
width
:
diameter
,
height
:
diameter
)
view
.
layout
(
menuView
)
.
width
(
diameter
)
.
height
(
diameter
)
.
bottom
(
16
)
.
centerHorizontally
()
view
.
layout
.
alignFromBottomLeft
(
menuView
,
bottom
:
16
,
left
:
(
view
.
bounds
.
width
-
diameter
)
/
2
)
}
}
}
}
Examples/Programmatic/SearchBar/SearchBar/ViewController.swift
View file @
d52bee10
...
@@ -59,7 +59,7 @@ class ViewController: UIViewController {
...
@@ -59,7 +59,7 @@ class ViewController: UIViewController {
/// Prepares the containerView.
/// Prepares the containerView.
private
func
prepareContainerView
()
{
private
func
prepareContainerView
()
{
containerView
=
UIView
()
containerView
=
UIView
()
view
.
layout
.
align
(
containerView
,
top
:
100
,
left
:
20
,
right
:
20
)
view
.
layout
(
containerView
)
.
edges
(
top
:
100
,
left
:
20
,
right
:
20
)
}
}
/// Prepares the toolbar
/// Prepares the toolbar
...
...
Examples/Programmatic/SideNavigationController/SideNavigationController/AppLeftViewController.swift
View file @
d52bee10
...
@@ -75,7 +75,7 @@ class AppLeftViewController: UIViewController {
...
@@ -75,7 +75,7 @@ class AppLeftViewController: UIViewController {
tableView
.
separatorStyle
=
.
None
tableView
.
separatorStyle
=
.
None
// Use Layout to easily align the tableView.
// Use Layout to easily align the tableView.
view
.
layout
.
align
.
edges
(
tableView
)
view
.
layout
(
tableView
)
.
edges
(
top
:
170
)
}
}
}
}
...
...
Examples/Programmatic/TableCardView/TableCardView/ViewController.swift
View file @
d52bee10
...
@@ -117,7 +117,7 @@ class ViewController: UIViewController {
...
@@ -117,7 +117,7 @@ class ViewController: UIViewController {
cardView
.
leftButtons
=
[
closeButton
]
cardView
.
leftButtons
=
[
closeButton
]
cardView
.
rightButtons
=
[
settingButton
]
cardView
.
rightButtons
=
[
settingButton
]
view
.
layout
.
align
(
cardView
,
left
:
10
,
right
:
10
,
top
:
100
,
bottom
:
100
)
view
.
layout
(
cardView
)
.
edges
(
left
:
10
,
right
:
10
,
top
:
100
,
bottom
:
100
)
}
}
}
}
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
d52bee10
...
@@ -70,8 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -70,8 +70,7 @@ class ViewController: UIViewController, TextFieldDelegate {
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Normal
)
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Normal
)
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Highlighted
)
btn
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Highlighted
)
view
.
layout
.
size
(
btn
,
width
:
100
,
height
:
50
)
view
.
layout
(
btn
)
.
width
(
100
)
.
height
(
50
)
.
bottom
(
24
)
.
right
(
24
)
view
.
layout
.
alignFromBottomRight
(
btn
,
bottom
:
24
,
right
:
24
)
}
}
/// Handle the resign responder button.
/// Handle the resign responder button.
...
@@ -93,8 +92,7 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -93,8 +92,7 @@ class ViewController: UIViewController, TextFieldDelegate {
// Size the TextField to the maximum width, less 40 pixels on either side
// Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 40 pixels.
// with a top margin of 40 pixels.
view
.
layout
.
alignFromTop
(
nameField
,
top
:
40
)
view
.
layout
(
nameField
)
.
top
(
40
)
.
horizontally
(
left
:
40
,
right
:
40
)
view
.
layout
.
horizontally
(
nameField
,
left
:
40
,
right
:
40
)
}
}
/// Prepares the email TextField.
/// Prepares the email TextField.
...
@@ -125,8 +123,7 @@ class ViewController: UIViewController, TextFieldDelegate {
...
@@ -125,8 +123,7 @@ class ViewController: UIViewController, TextFieldDelegate {
// Size the TextField to the maximum width, less 40 pixels on either side
// Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 200 pixels.
// with a top margin of 200 pixels.
view
.
layout
.
alignFromTop
(
passwordField
,
top
:
200
)
view
.
layout
(
passwordField
)
.
top
(
200
)
.
horizontally
(
left
:
40
,
right
:
40
)
view
.
layout
.
horizontally
(
passwordField
,
left
:
40
,
right
:
40
)
}
}
/// Executed when the 'return' key is pressed when using the emailField.
/// Executed when the 'return' key is pressed when using the emailField.
...
...
Examples/Programmatic/TextView/TextView/ViewController.swift
View file @
d52bee10
...
@@ -75,7 +75,7 @@ class ViewController: UIViewController, TextDelegate {
...
@@ -75,7 +75,7 @@ class ViewController: UIViewController, TextDelegate {
textView
.
titleLabelColor
=
MaterialColor
.
grey
.
base
textView
.
titleLabelColor
=
MaterialColor
.
grey
.
base
textView
.
titleLabelActiveColor
=
MaterialColor
.
blue
.
accent3
textView
.
titleLabelActiveColor
=
MaterialColor
.
blue
.
accent3
view
.
layout
.
align
(
textView
!
,
top
:
124
,
left
:
24
,
bottom
:
24
,
right
:
24
)
view
.
layout
(
textView
!
)
.
edges
(
top
:
124
,
left
:
24
,
bottom
:
24
,
right
:
24
)
}
}
/**
/**
...
...
Examples/Programmatic/Toolbar/Toolbar/ViewController.swift
View file @
d52bee10
...
@@ -59,7 +59,7 @@ class ViewController: UIViewController {
...
@@ -59,7 +59,7 @@ class ViewController: UIViewController {
/// Prepares the containerView.
/// Prepares the containerView.
private
func
prepareContainerView
()
{
private
func
prepareContainerView
()
{
containerView
=
UIView
()
containerView
=
UIView
()
view
.
layout
.
align
.
edges
(
containerView
,
top
:
100
,
left
:
20
,
right
:
20
)
view
.
layout
(
containerView
)
.
edges
(
top
:
100
,
left
:
20
,
right
:
20
)
}
}
/// Prepares the toolbar
/// Prepares the toolbar
...
...
Examples/Storyboards/SideNavigationController/SideNavigationController/MainViewController.swift
View file @
d52bee10
...
@@ -43,8 +43,7 @@ class RootViewController: UIViewController {
...
@@ -43,8 +43,7 @@ class RootViewController: UIViewController {
fabButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
fabButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
fabButton
.
addTarget
(
self
,
action
:
#selector(
handleFabButton
)
,
forControlEvents
:
.
TouchUpInside
)
fabButton
.
addTarget
(
self
,
action
:
#selector(
handleFabButton
)
,
forControlEvents
:
.
TouchUpInside
)
view
.
layout
.
size
(
fabButton
,
width
:
64
,
height
:
64
)
view
.
layout
(
fabButton
)
.
width
(
64
)
.
height
(
64
)
.
bottom
(
16
)
.
right
(
16
)
view
.
layout
.
alignFromBottomRight
(
fabButton
,
bottom
:
16
,
right
:
16
)
}
}
// FabButton handler.
// FabButton handler.
...
...
Sources/iOS/BottomTabBar.swift
View file @
d52bee10
...
@@ -233,8 +233,8 @@ public class BottomTabBar : UITabBar {
...
@@ -233,8 +233,8 @@ public class BottomTabBar : UITabBar {
super
.
didMoveToSuperview
()
super
.
didMoveToSuperview
()
if
autoLayoutToSuperview
{
if
autoLayoutToSuperview
{
if
let
v
:
UIView
=
superview
{
if
let
v
:
UIView
=
superview
{
v
.
layout
.
align
.
bottom
(
self
)
v
.
layout
(
self
)
.
bottom
(
)
v
.
layout
.
horizontally
(
self
)
v
.
layout
(
self
)
.
horizontally
(
)
}
}
}
}
}
}
...
...
Sources/iOS/CardView.swift
View file @
d52bee10
...
@@ -277,7 +277,7 @@ public class CardView : MaterialPulseView {
...
@@ -277,7 +277,7 @@ public class CardView : MaterialPulseView {
verticalFormat
+=
"-[titleLabel]"
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
views
[
"titleLabel"
]
=
v
layout
.
horizontally
(
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
}
// detail
// detail
...
@@ -292,7 +292,7 @@ public class CardView : MaterialPulseView {
...
@@ -292,7 +292,7 @@ public class CardView : MaterialPulseView {
verticalFormat
+=
"-[contentView]"
verticalFormat
+=
"-[contentView]"
views
[
"contentView"
]
=
v
views
[
"contentView"
]
=
v
layout
.
horizontally
(
v
,
left
:
contentInset
.
left
+
contentViewInset
.
left
,
right
:
contentInset
.
right
+
contentViewInset
.
right
)
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
contentViewInset
.
left
,
right
:
contentInset
.
right
+
contentViewInset
.
right
)
}
}
// leftButtons
// leftButtons
...
@@ -314,7 +314,7 @@ public class CardView : MaterialPulseView {
...
@@ -314,7 +314,7 @@ public class CardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
h
+=
"[
\(
k
)
]"
layout
.
align
.
bottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
i
+=
1
i
+=
1
}
}
...
@@ -343,7 +343,7 @@ public class CardView : MaterialPulseView {
...
@@ -343,7 +343,7 @@ public class CardView : MaterialPulseView {
h
+=
"-(right_left)-"
h
+=
"-(right_left)-"
}
}
layout
.
align
.
bottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
i
-=
1
i
-=
1
}
}
...
...
Sources/iOS/ImageCardView.swift
View file @
d52bee10
...
@@ -378,9 +378,9 @@ public class ImageCardView : MaterialPulseView {
...
@@ -378,9 +378,9 @@ public class ImageCardView : MaterialPulseView {
verticalFormat
+=
"-[titleLabel]"
verticalFormat
+=
"-[titleLabel]"
views
[
"titleLabel"
]
=
v
views
[
"titleLabel"
]
=
v
}
else
{
}
else
{
layout
.
align
.
top
(
v
,
top
:
contentInset
.
top
+
titleLabelInset
.
top
)
layout
(
v
)
.
top
(
contentInset
.
top
+
titleLabelInset
.
top
)
}
}
layout
.
horizontally
(
v
,
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
titleLabelInset
.
left
,
right
:
contentInset
.
right
+
titleLabelInset
.
right
)
}
}
// detail
// detail
...
@@ -395,7 +395,7 @@ public class ImageCardView : MaterialPulseView {
...
@@ -395,7 +395,7 @@ public class ImageCardView : MaterialPulseView {
verticalFormat
+=
"-[contentView]"
verticalFormat
+=
"-[contentView]"
views
[
"contentView"
]
=
v
views
[
"contentView"
]
=
v
layout
.
horizontally
(
v
,
left
:
contentInset
.
left
+
contentViewInset
.
left
,
right
:
contentInset
.
right
+
contentViewInset
.
right
)
layout
(
v
)
.
horizontally
(
left
:
contentInset
.
left
+
contentViewInset
.
left
,
right
:
contentInset
.
right
+
contentViewInset
.
right
)
}
}
// leftButtons
// leftButtons
...
@@ -417,7 +417,7 @@ public class ImageCardView : MaterialPulseView {
...
@@ -417,7 +417,7 @@ public class ImageCardView : MaterialPulseView {
h
+=
"[
\(
k
)
]"
h
+=
"[
\(
k
)
]"
layout
.
align
.
bottom
(
b
,
bottom
:
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
leftButtonsInset
.
bottom
)
i
+=
1
i
+=
1
}
}
...
@@ -446,7 +446,7 @@ public class ImageCardView : MaterialPulseView {
...
@@ -446,7 +446,7 @@ public class ImageCardView : MaterialPulseView {
h
+=
"-(right_left)-"
h
+=
"-(right_left)-"
}
}
layout
.
align
.
bottom
(
b
,
bottom
:
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
layout
(
b
)
.
bottom
(
contentInset
.
bottom
+
rightButtonsInset
.
bottom
)
i
-=
1
i
-=
1
}
}
...
...
Sources/iOS/Layout.swift
View file @
d52bee10
...
@@ -30,158 +30,455 @@
...
@@ -30,158 +30,455 @@
import
UIKit
import
UIKit
public
class
Align
{
public
class
Layout
{
/// Reference to Align.
/// UIView context.
/// UIView context.
internal
weak
var
context
:
UIView
?
internal
weak
var
context
:
UIView
?
/// Child UIView context.
internal
weak
var
childContext
:
UIView
?
init
(
context
:
UIView
?)
{
init
(
context
:
UIView
?)
{
self
.
context
=
context
self
.
context
=
context
}
}
/// Edges
init
(
context
:
UIView
?,
childContext
:
UIView
?)
{
public
func
edges
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
self
.
context
=
context
self
.
childContext
=
childContext
}
/// Width
/// - returns: layout instance
public
func
width
(
child
:
UIView
,
width
:
CGFloat
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignToParent
(
v
,
child
:
child
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
Layout
.
width
(
v
,
child
:
child
,
width
:
width
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// TopLeft
/// Width (Assuming a child context)
public
func
topLeft
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
/// - returns: current layout instance
if
let
v
:
UIView
=
context
{
public
func
width
(
width
:
CGFloat
)
->
Layout
{
Layout
.
alignFromTopLeft
(
v
,
child
:
child
,
top
:
top
,
left
:
left
)
if
let
c
:
UIView
=
childContext
{
self
.
width
(
c
,
width
:
width
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
return
self
}
}
/// TopRight
/// Height
public
func
topRight
(
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
height
(
child
:
UIView
,
height
:
CGFloat
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromTopRight
(
v
,
child
:
child
,
top
:
top
,
right
:
right
)
Layout
.
height
(
v
,
child
:
child
,
height
:
height
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
return
self
}
/// Height (Assuming a child context)
/// - returns: current layout instance
public
func
height
(
height
:
CGFloat
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
self
.
height
(
c
,
height
:
height
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
return
self
}
}
/// BottomLeft
/// Size
public
func
bottomLeft
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
size
(
child
:
UIView
,
width
:
CGFloat
,
height
:
CGFloat
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromBottomLeft
(
v
,
child
:
child
,
bottom
:
bottom
,
left
:
left
)
Layout
.
size
(
v
,
child
:
child
,
width
:
width
,
height
:
height
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
/// Size (Assuming a child context)
/// - returns: current layout instance
public
func
size
(
width
width
:
CGFloat
,
height
:
CGFloat
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
size
(
c
,
width
:
width
,
height
:
height
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
}
/// BottomRight
/// Array of UIViews horizontally aligned.
public
func
bottomRight
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
horizontally
(
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromBottomRight
(
v
,
child
:
child
,
bottom
:
bottom
,
right
:
right
)
Layout
.
alignToParentHorizontally
(
v
,
children
:
children
,
left
:
left
,
right
:
right
,
spacing
:
spacing
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Top
/// Array of UIViews vertically aligned.
public
func
top
(
child
:
UIView
,
top
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
vertically
(
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromTop
(
v
,
child
:
child
,
top
:
top
)
Layout
.
alignToParentVertically
(
v
,
children
:
children
,
top
:
top
,
bottom
:
bottom
,
spacing
:
spacing
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Left
/// Horizontally aligned.
public
func
left
(
child
:
UIView
,
left
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
horizontally
(
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromLeft
(
v
,
child
:
child
,
left
:
left
)
Layout
.
alignToParentHorizontally
(
v
,
child
:
child
,
left
:
left
,
right
:
right
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
return
self
}
/// Horizontally aligned (Assuming a child context)
/// - returns: current layout instance
public
func
horizontally
(
left
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
horizontally
(
c
,
left
:
left
,
right
:
right
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
return
self
}
}
/// Bottom
/// Vertically aligned.
public
func
bottom
(
child
:
UIView
,
bottom
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
vertically
(
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromBottom
(
v
,
child
:
child
,
bottom
:
bottom
)
Layout
.
alignToParentVertically
(
v
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
return
self
}
}
/// Vertically aligned (Assuming a child context)
/// - returns: current layout instance
public
func
vertically
(
top
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
vertically
(
c
,
top
:
top
,
bottom
:
bottom
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
/// Right
return
self
public
func
right
(
child
:
UIView
,
right
:
CGFloat
=
0
)
{
}
/// Center
/// - returns: current layout instance
public
func
center
(
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignFromRight
(
v
,
child
:
child
,
right
:
right
)
Layout
.
center
(
v
,
child
:
child
,
constantX
:
constantX
,
constantY
:
constantY
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
}
public
class
Layout
{
/// Center (Assuming a child context)
/// Reference to Align.
/// - returns: current layout instance
public
private(set)
var
align
:
Align
public
func
center
(
constantX
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
center
(
c
,
constantX
:
constantX
,
constantY
:
constantY
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
/// UIView context.
return
self
internal
weak
var
context
:
UIView
?
}
init
(
context
:
UIView
?)
{
/// Center Horizontally
self
.
context
=
context
/// - returns: current layout instance
self
.
align
=
Align
(
context
:
context
)
public
func
centerHorizontally
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
Layout
.
centerHorizontally
(
v
,
child
:
child
,
constant
:
constant
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
/// Width
return
self
public
func
width
(
child
:
UIView
,
width
:
CGFloat
=
0
)
{
}
/// Center Horizontally (Assuming a child context)
/// - returns: current layout instance
public
func
centerHorizontally
(
constant
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
centerHorizontally
(
c
,
constant
:
constant
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Center Vertically
/// - returns: current layout instance
public
func
centerVertically
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
width
(
v
,
child
:
child
,
width
:
width
)
Layout
.
centerVertically
(
v
,
child
:
child
,
constant
:
constant
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Height
/// Center Vertically (Assuming a child context)
public
func
height
(
child
:
UIView
,
height
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
centerVertically
(
constant
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
centerVertically
(
c
,
constant
:
constant
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align Edges
/// - returns: current layout instance
public
func
edges
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
height
(
v
,
child
:
child
,
height
:
height
)
Layout
.
alignToParent
(
v
,
child
:
child
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Size
/// Align Edges (Assuming a child context)
public
func
size
(
child
:
UIView
,
width
:
CGFloat
=
0
,
height
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
edges
(
top
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
edges
(
c
,
top
:
top
,
left
:
left
,
bottom
:
bottom
,
right
:
right
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to TopLeft
/// - returns: current layout instance
public
func
topLeft
(
child
:
UIView
,
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
size
(
v
,
child
:
child
,
width
:
width
,
height
:
height
)
Layout
.
alignFromTopLeft
(
v
,
child
:
child
,
top
:
top
,
left
:
left
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
return
self
}
}
/// Align to TopLeft (Assuming a child context)
/// - returns: current layout instance
public
func
topLeft
(
top
top
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
topLeft
(
c
,
top
:
top
,
left
:
left
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
/// Array of UIViews horizontally aligned.
return
self
public
func
horizontally
(
children
:
Array
<
UIView
>
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
}
/// Align to TopRight
/// - returns: current layout instance
public
func
topRight
(
child
:
UIView
,
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignToParentHorizontally
(
v
,
children
:
children
,
left
:
left
,
right
:
right
,
spacing
:
spacing
)
Layout
.
alignFromTopRight
(
v
,
child
:
child
,
top
:
top
,
right
:
right
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Array of UIViews vertically aligned.
/// Align to TopRight (Assuming a child context)
public
func
vertically
(
children
:
Array
<
UIView
>
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
,
spacing
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
topRight
(
top
top
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
topRight
(
c
,
top
:
top
,
right
:
right
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to BottomLeft
/// - returns: current layout instance
public
func
bottomLeft
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignToParentVertically
(
v
,
children
:
children
,
top
:
top
,
bottom
:
bottom
,
spacing
:
spacing
)
Layout
.
alignFromBottomLeft
(
v
,
child
:
child
,
bottom
:
bottom
,
left
:
left
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Horizontally aligned.
/// Align to BottomLeft (Assuming a child context)
public
func
horizontally
(
child
:
UIView
,
left
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
bottomLeft
(
bottom
bottom
:
CGFloat
=
0
,
left
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
bottomLeft
(
c
,
bottom
:
bottom
,
left
:
left
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to BottomRight
/// - returns: current layout instance
public
func
bottomRight
(
child
:
UIView
,
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignToParentHorizontally
(
v
,
child
:
child
,
left
:
left
,
right
:
right
)
Layout
.
alignFromBottomRight
(
v
,
child
:
child
,
bottom
:
bottom
,
right
:
right
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Vertically aligned.
/// Align to BottomRight (Assuming a child context)
public
func
vertically
(
child
:
UIView
,
top
:
CGFloat
=
0
,
bottom
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
bottomRight
(
bottom
bottom
:
CGFloat
=
0
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
bottomRight
(
c
,
bottom
:
bottom
,
right
:
right
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to Top
/// - returns: current layout instance
public
func
top
(
child
:
UIView
,
top
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
alignToParentVertically
(
v
,
child
:
child
,
top
:
top
,
bottom
:
bottom
)
Layout
.
alignFromTop
(
v
,
child
:
child
,
top
:
top
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// Center
/// Align to Top (Assuming a child context)
public
func
center
(
child
:
UIView
,
constantX
:
CGFloat
=
0
,
constantY
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
top
(
top
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
self
.
top
(
c
,
top
:
top
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to Left
/// - returns: current layout instance
public
func
left
(
child
:
UIView
,
left
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
center
(
v
,
child
:
child
,
constantX
:
constantX
,
constantY
:
constantY
)
Layout
.
alignFromLeft
(
v
,
child
:
child
,
left
:
left
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
return
self
}
}
/// Align to Left (Assuming a child context)
/// - returns: current layout instance
public
func
left
(
left
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
self
.
left
(
c
,
left
:
left
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
}
/// CenterHorizontally
return
self
public
func
centerHorizontally
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
}
/// Align to Bottom
/// - returns: current layout instance
public
func
bottom
(
child
:
UIView
,
bottom
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
centerHorizontally
(
v
,
child
:
child
,
constant
:
constant
)
Layout
.
alignFromBottom
(
v
,
child
:
child
,
bottom
:
bottom
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
}
/// CenterVertically
/// Align to Bottom (Assuming a child context)
public
func
centerVertically
(
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
/// - returns: current layout instance
public
func
bottom
(
bottom
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
self
.
bottom
(
c
,
bottom
:
bottom
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
/// Align to Right
/// - returns: current layout instance
public
func
right
(
child
:
UIView
,
right
:
CGFloat
=
0
)
->
Layout
{
if
let
v
:
UIView
=
context
{
if
let
v
:
UIView
=
context
{
Layout
.
centerVertically
(
v
,
child
:
child
,
constant
:
constant
)
Layout
.
alignFromRight
(
v
,
child
:
child
,
right
:
right
)
}
else
{
debugPrint
(
"Parent context not available."
)
}
}
return
self
}
/// Align to Right (Assuming a child context)
/// - returns: current layout instance
public
func
right
(
right
:
CGFloat
=
0
)
->
Layout
{
if
let
c
:
UIView
=
childContext
{
self
.
right
(
c
,
right
:
right
)
}
else
{
debugPrint
(
"Child view context not available."
)
}
return
self
}
}
}
}
...
@@ -364,4 +661,10 @@ public extension UIView {
...
@@ -364,4 +661,10 @@ public extension UIView {
MaterialAssociateObject
(
self
,
key
:
&
LayoutKey
,
value
:
value
)
MaterialAssociateObject
(
self
,
key
:
&
LayoutKey
,
value
:
value
)
}
}
}
}
/// Layout reference with a child context.
public
func
layout
(
child
:
UIView
)
->
Layout
{
return
Layout
(
context
:
self
,
childContext
:
child
)
}
}
}
Sources/iOS/TextView.swift
View file @
d52bee10
...
@@ -401,7 +401,7 @@ public class TextView: UITextView {
...
@@ -401,7 +401,7 @@ public class TextView: UITextView {
internal
func
reloadView
()
{
internal
func
reloadView
()
{
if
let
p
=
placeholderLabel
{
if
let
p
=
placeholderLabel
{
removeConstraints
(
constraints
)
removeConstraints
(
constraints
)
layout
.
align
.
edges
(
p
,
layout
(
p
)
.
edges
(
top
:
textContainerInset
.
top
,
top
:
textContainerInset
.
top
,
left
:
textContainerInset
.
left
+
textContainer
.
lineFragmentPadding
,
left
:
textContainerInset
.
left
+
textContainer
.
lineFragmentPadding
,
bottom
:
textContainerInset
.
bottom
,
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