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
4af601ee
Unverified
Commit
4af601ee
authored
Jun 05, 2016
by
M. Porooshani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added centering methods to MaterialLayout with examples
parent
9c040edc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
Examples/Programmatic/MaterialLayout/MaterialLayout/ViewController.swift
+45
-0
Sources/iOS/MaterialLayout.swift
+17
-0
No files found.
Examples/Programmatic/MaterialLayout/MaterialLayout/ViewController.swift
View file @
4af601ee
...
...
@@ -43,6 +43,7 @@ class ViewController: UIViewController {
prepareView
()
prepareAlignToParentHorizontallyExample
()
prepareAlignToParentVerticallyExample
()
prepareCenterExample
()
}
/// General preparation statements.
...
...
@@ -141,5 +142,49 @@ class ViewController: UIViewController {
print
(
v
.
frame
)
}
}
// Lays out test views to the center of different axes
private
func
prepareCenterExample
()
{
let
length
:
CGFloat
=
100
let
labelCX
=
UILabel
()
labelCX
.
backgroundColor
=
MaterialColor
.
grey
.
base
labelCX
.
text
=
"centerX"
labelCX
.
textAlignment
=
.
Center
labelCX
.
layer
.
cornerRadius
=
length
/
2.0
labelCX
.
clipsToBounds
=
true
view
.
addSubview
(
labelCX
)
MaterialLayout
.
width
(
view
,
child
:
labelCX
,
width
:
length
)
MaterialLayout
.
height
(
view
,
child
:
labelCX
,
height
:
length
)
MaterialLayout
.
centerHorizontally
(
view
,
child
:
labelCX
)
let
labelCY
=
UILabel
()
labelCY
.
backgroundColor
=
MaterialColor
.
grey
.
base
labelCY
.
text
=
"centerY"
labelCY
.
textAlignment
=
.
Center
labelCY
.
layer
.
cornerRadius
=
length
/
2.0
labelCY
.
clipsToBounds
=
true
view
.
addSubview
(
labelCY
)
MaterialLayout
.
width
(
view
,
child
:
labelCY
,
width
:
length
)
MaterialLayout
.
height
(
view
,
child
:
labelCY
,
height
:
length
)
MaterialLayout
.
centerVertically
(
view
,
child
:
labelCY
)
let
labelCXY
=
UILabel
()
labelCXY
.
backgroundColor
=
MaterialColor
.
grey
.
base
labelCXY
.
text
=
"centerXY"
labelCXY
.
textAlignment
=
.
Center
labelCXY
.
layer
.
cornerRadius
=
length
/
2.0
labelCXY
.
clipsToBounds
=
true
view
.
addSubview
(
labelCXY
)
MaterialLayout
.
width
(
view
,
child
:
labelCXY
,
width
:
length
)
MaterialLayout
.
height
(
view
,
child
:
labelCXY
,
height
:
length
)
MaterialLayout
.
center
(
view
,
child
:
labelCXY
)
}
}
Sources/iOS/MaterialLayout.swift
View file @
4af601ee
...
...
@@ -147,7 +147,24 @@ public struct MaterialLayout {
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
Right
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
Right
,
multiplier
:
1.0
,
constant
:
-
right
))
}
/// CenterHorizontally
public
static
func
centerHorizontally
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
([
child
])
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterX
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterX
,
multiplier
:
1.0
,
constant
:
constant
))
}
/// CenterVertically
public
static
func
centerVertically
(
parent
:
UIView
,
child
:
UIView
,
constant
:
CGFloat
=
0
)
{
prepareForConstraint
([
child
])
parent
.
addConstraint
(
NSLayoutConstraint
(
item
:
child
,
attribute
:
.
CenterY
,
relatedBy
:
.
Equal
,
toItem
:
parent
,
attribute
:
.
CenterY
,
multiplier
:
1.0
,
constant
:
constant
))
}
/// 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
)
}
/// prepareForConstraint
private
static
func
prepareForConstraint
(
views
:
[
UIView
])
{
for
v
in
views
{
...
...
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