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
50d1b21d
Commit
50d1b21d
authored
Feb 11, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated Grid interface
parent
c524d017
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
122 deletions
+147
-122
Examples/Programmatic/GridView/GridView.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/GridView/GridView/ViewController.swift
+57
-55
Sources/Grid.swift
+84
-67
No files found.
Examples/Programmatic/GridView/GridView.xcodeproj/project.pbxproj
View file @
50d1b21d
...
...
@@ -7,6 +7,8 @@
objects
=
{
/* Begin PBXBuildFile section */
9656CD121C6C664700EBCEF1
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9656CD111C6C664700EBCEF1
/* Material.framework */
;
};
9656CD131C6C664700EBCEF1
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9656CD111C6C664700EBCEF1
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
965C58CD1C6B936400CFB4E1
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965C58CC1C6B936400CFB4E1
/* AppDelegate.swift */
;
};
965C58CF1C6B936400CFB4E1
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965C58CE1C6B936400CFB4E1
/* ViewController.swift */
;
};
965C58D41C6B936400CFB4E1
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965C58D31C6B936400CFB4E1
/* Assets.xcassets */
;
};
...
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
9656CD131C6C664700EBCEF1
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9656CD111C6C664700EBCEF1
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
965C58C91C6B936400CFB4E1
/* GridView.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
GridView.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
965C58CC1C6B936400CFB4E1
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
965C58CE1C6B936400CFB4E1
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
9656CD121C6C664700EBCEF1
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -49,6 +54,7 @@
965C58C01C6B936400CFB4E1
=
{
isa
=
PBXGroup
;
children
=
(
9656CD111C6C664700EBCEF1
/* Material.framework */
,
965C58CB1C6B936400CFB4E1
/* GridView */
,
965C58CA1C6B936400CFB4E1
/* Products */
,
);
...
...
Examples/Programmatic/GridView/GridView/ViewController.swift
View file @
50d1b21d
...
...
@@ -57,57 +57,57 @@ class ViewController: UIViewController {
private
func
prepareLargeCardViewExample
()
{
let
cardView
:
MaterialPulseView
=
MaterialPulseView
(
frame
:
CGRectMake
(
16
,
100
,
view
.
bounds
.
width
-
32
,
350
))
cardView
.
pulseColor
=
MaterialColor
.
blueGrey
.
lighten5
cardView
.
grid
.
axis
=
.
Vertical
cardView
.
grid
.
axis
.
direction
=
.
Vertical
cardView
.
depth
=
.
Depth1
view
.
addSubview
(
cardView
)
let
imageView
:
MaterialView
=
MaterialView
()
imageView
.
grid
.
row
=
.
Row
7
imageView
.
grid
.
column
=
.
Column
6
imageView
.
grid
.
row
s
=
7
imageView
.
grid
.
column
s
=
6
imageView
.
grid
.
spacing
=
4
cardView
.
addSubview
(
imageView
)
var
image
:
UIImage
?
=
UIImage
(
named
:
"CosmicMindInverted"
)
let
leftImageViewCollection
:
MaterialView
=
MaterialView
()
leftImageViewCollection
.
grid
.
column
=
.
Column
3
leftImageViewCollection
.
grid
.
column
s
=
3
leftImageViewCollection
.
image
=
image
leftImageViewCollection
.
contentsGravity
=
.
ResizeAspectFill
imageView
.
addSubview
(
leftImageViewCollection
)
let
rightImageViewCollection
:
MaterialView
=
MaterialView
()
rightImageViewCollection
.
grid
.
column
=
.
Column
3
rightImageViewCollection
.
grid
.
axis
=
.
Vertical
rightImageViewCollection
.
grid
.
column
s
=
3
rightImageViewCollection
.
grid
.
axis
.
direction
=
.
Vertical
rightImageViewCollection
.
grid
.
spacing
=
4
imageView
.
addSubview
(
rightImageViewCollection
)
image
=
UIImage
(
named
:
"CosmicMindInverted"
)
let
topImageViewCollection
:
MaterialView
=
MaterialView
()
topImageViewCollection
.
grid
.
row
=
.
Row
6
topImageViewCollection
.
grid
.
row
s
=
6
topImageViewCollection
.
image
=
image
topImageViewCollection
.
contentsGravity
=
.
ResizeAspectFill
rightImageViewCollection
.
addSubview
(
topImageViewCollection
)
image
=
UIImage
(
named
:
"CosmicMindInverted"
)
let
bottomImageViewCollection
:
MaterialView
=
MaterialView
()
bottomImageViewCollection
.
grid
.
row
=
.
Row
6
bottomImageViewCollection
.
grid
.
row
s
=
6
bottomImageViewCollection
.
image
=
image
bottomImageViewCollection
.
contentsGravity
=
.
ResizeAspectFill
rightImageViewCollection
.
addSubview
(
bottomImageViewCollection
)
let
contentView
:
MaterialView
=
MaterialView
()
contentView
.
grid
.
row
=
.
Row
5
contentView
.
grid
.
axis
=
.
Vertical
contentView
.
grid
.
row
s
=
5
contentView
.
grid
.
axis
.
direction
=
.
Vertical
contentView
.
grid
.
contentInsetPreset
=
.
Square3
contentView
.
backgroundColor
=
MaterialColor
.
clear
cardView
.
addSubview
(
contentView
)
let
titleView
:
MaterialView
=
MaterialView
()
titleView
.
grid
.
row
=
.
Row
1
titleView
.
grid
.
row
s
=
1
titleView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
titleView
)
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
grid
.
column
=
.
Column
7
titleLabel
.
grid
.
column
s
=
7
titleLabel
.
text
=
"Material"
titleLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
titleLabel
.
backgroundColor
=
MaterialColor
.
clear
...
...
@@ -115,8 +115,8 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_more_vert_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
moreButton
:
FlatButton
=
FlatButton
()
moreButton
.
grid
.
column
=
.
Column
1
moreButton
.
grid
.
columnOffset
=
.
Column
4
moreButton
.
grid
.
column
s
=
1
moreButton
.
grid
.
offset
.
columns
=
4
moreButton
.
contentInsetPreset
=
.
None
moreButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
moreButton
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -125,7 +125,7 @@ class ViewController: UIViewController {
titleView
.
addSubview
(
moreButton
)
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
grid
.
row
=
.
Row
3
detailLabel
.
grid
.
row
s
=
3
detailLabel
.
numberOfLines
=
0
detailLabel
.
lineBreakMode
=
.
ByTruncatingTail
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
...
...
@@ -135,12 +135,12 @@ class ViewController: UIViewController {
contentView
.
addSubview
(
detailLabel
)
let
alarmView
:
MaterialView
=
MaterialView
()
alarmView
.
grid
.
row
=
.
Row
1
alarmView
.
grid
.
row
s
=
1
alarmView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
alarmView
)
let
alarmLabel
:
UILabel
=
UILabel
()
alarmLabel
.
grid
.
column
=
.
Column
7
alarmLabel
.
grid
.
column
s
=
7
alarmLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
alarmLabel
.
text
=
"34 min"
alarmLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -149,8 +149,8 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_alarm_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
alarmButton
:
FlatButton
=
FlatButton
()
alarmButton
.
grid
.
column
=
.
Column
1
alarmButton
.
grid
.
columnOffset
=
.
Column
4
alarmButton
.
grid
.
column
s
=
1
alarmButton
.
grid
.
offset
.
columns
=
4
alarmButton
.
contentInsetPreset
=
.
None
alarmButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
alarmButton
.
tintColor
=
MaterialColor
.
red
.
base
...
...
@@ -175,27 +175,27 @@ class ViewController: UIViewController {
var
image
:
UIImage
?
=
UIImage
(
named
:
"CosmicMindInverted"
)
let
imageView
:
MaterialView
=
MaterialView
()
imageView
.
grid
.
column
=
.
Column
6
imageView
.
grid
.
column
s
=
6
imageView
.
image
=
image
imageView
.
contentsGravity
=
.
ResizeAspectFill
cardView
.
addSubview
(
imageView
)
let
contentView
:
MaterialView
=
MaterialView
()
contentView
.
grid
.
column
=
.
Column
6
contentView
.
grid
.
axis
=
.
Vertical
contentView
.
grid
.
column
s
=
6
contentView
.
grid
.
axis
.
direction
=
.
Vertical
contentView
.
grid
.
contentInsetPreset
=
.
Square3
contentView
.
grid
.
spacing
=
8
contentView
.
backgroundColor
=
MaterialColor
.
clear
cardView
.
addSubview
(
contentView
)
let
titleView
:
MaterialView
=
MaterialView
()
titleView
.
grid
.
column
=
.
Column
6
titleView
.
grid
.
row
=
.
Row
2
titleView
.
grid
.
column
s
=
6
titleView
.
grid
.
row
s
=
2
titleView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
titleView
)
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
grid
.
column
=
.
Column
5
titleLabel
.
grid
.
column
s
=
5
titleLabel
.
text
=
"Material"
titleLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
titleLabel
.
backgroundColor
=
MaterialColor
.
clear
...
...
@@ -203,7 +203,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_more_vert_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
moreButton
:
FlatButton
=
FlatButton
()
moreButton
.
grid
.
column
=
.
Column
1
moreButton
.
grid
.
column
s
=
1
moreButton
.
contentInsetPreset
=
.
None
moreButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
moreButton
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -212,7 +212,7 @@ class ViewController: UIViewController {
titleView
.
addSubview
(
moreButton
)
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
grid
.
row
=
.
Row
8
detailLabel
.
grid
.
row
s
=
8
detailLabel
.
numberOfLines
=
0
detailLabel
.
lineBreakMode
=
.
ByTruncatingTail
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
...
...
@@ -222,13 +222,13 @@ class ViewController: UIViewController {
contentView
.
addSubview
(
detailLabel
)
let
alarmView
:
MaterialView
=
MaterialView
()
alarmView
.
grid
.
column
=
.
Column
6
alarmView
.
grid
.
row
=
.
Row
2
alarmView
.
grid
.
column
s
=
6
alarmView
.
grid
.
row
s
=
2
alarmView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
alarmView
)
let
alarmLabel
:
UILabel
=
UILabel
()
alarmLabel
.
grid
.
column
=
.
Column
5
alarmLabel
.
grid
.
column
s
=
5
alarmLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
alarmLabel
.
text
=
"34 min"
alarmLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -237,7 +237,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_alarm_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
alarmButton
:
FlatButton
=
FlatButton
()
alarmButton
.
grid
.
column
=
.
Column
1
alarmButton
.
grid
.
column
s
=
1
alarmButton
.
contentInsetPreset
=
.
None
alarmButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
alarmButton
.
tintColor
=
MaterialColor
.
red
.
base
...
...
@@ -260,27 +260,27 @@ class ViewController: UIViewController {
var
image
:
UIImage
?
=
UIImage
(
named
:
"CosmicMindInverted"
)
let
imageView
:
MaterialView
=
MaterialView
()
imageView
.
grid
.
column
=
.
Column
4
imageView
.
grid
.
column
s
=
4
imageView
.
image
=
image
imageView
.
contentsGravity
=
.
ResizeAspectFill
cardView
.
addSubview
(
imageView
)
let
contentView
:
MaterialView
=
MaterialView
()
contentView
.
grid
.
column
=
.
Column
8
contentView
.
grid
.
axis
=
.
Vertical
contentView
.
grid
.
column
s
=
8
contentView
.
grid
.
axis
.
direction
=
.
Vertical
contentView
.
grid
.
contentInsetPreset
=
.
Square3
contentView
.
grid
.
spacing
=
12
contentView
.
backgroundColor
=
MaterialColor
.
clear
cardView
.
addSubview
(
contentView
)
let
titleView
:
MaterialView
=
MaterialView
()
titleView
.
grid
.
column
=
.
Column
8
titleView
.
grid
.
row
=
.
Row
4
titleView
.
grid
.
column
s
=
8
titleView
.
grid
.
row
s
=
4
titleView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
titleView
)
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
grid
.
column
=
.
Column
7
titleLabel
.
grid
.
column
s
=
7
titleLabel
.
text
=
"Material"
titleLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
titleLabel
.
backgroundColor
=
MaterialColor
.
clear
...
...
@@ -288,7 +288,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_more_vert_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
moreButton
:
FlatButton
=
FlatButton
()
moreButton
.
grid
.
column
=
.
Column
1
moreButton
.
grid
.
column
s
=
1
moreButton
.
contentInsetPreset
=
.
None
moreButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
moreButton
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -297,7 +297,7 @@ class ViewController: UIViewController {
titleView
.
addSubview
(
moreButton
)
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
grid
.
row
=
.
Row
4
detailLabel
.
grid
.
row
s
=
4
detailLabel
.
numberOfLines
=
0
detailLabel
.
lineBreakMode
=
.
ByTruncatingTail
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
...
...
@@ -307,13 +307,13 @@ class ViewController: UIViewController {
contentView
.
addSubview
(
detailLabel
)
let
alarmView
:
MaterialView
=
MaterialView
()
alarmView
.
grid
.
column
=
.
Column
8
alarmView
.
grid
.
row
=
.
Row
4
alarmView
.
grid
.
column
s
=
8
alarmView
.
grid
.
row
s
=
4
alarmView
.
backgroundColor
=
MaterialColor
.
clear
contentView
.
addSubview
(
alarmView
)
let
alarmLabel
:
UILabel
=
UILabel
()
alarmLabel
.
grid
.
column
=
.
Column
7
alarmLabel
.
grid
.
column
s
=
7
alarmLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
alarmLabel
.
text
=
"34 min"
alarmLabel
.
textColor
=
MaterialColor
.
blueGrey
.
darken4
...
...
@@ -322,7 +322,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_alarm_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
alarmButton
:
FlatButton
=
FlatButton
()
alarmButton
.
grid
.
column
=
.
Column
1
alarmButton
.
grid
.
column
s
=
1
alarmButton
.
contentInsetPreset
=
.
None
alarmButton
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
alarmButton
.
tintColor
=
MaterialColor
.
red
.
base
...
...
@@ -340,7 +340,7 @@ class ViewController: UIViewController {
private
func
prepareHorizontalGridViewExample
()
{
var
image
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn1
:
FlatButton
=
FlatButton
()
btn1
.
grid
.
column
=
.
Column
3
btn1
.
grid
.
column
s
=
3
btn1
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -350,7 +350,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_flash_off_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn2
:
FlatButton
=
FlatButton
()
btn2
.
grid
.
column
=
.
Column
3
btn2
.
grid
.
column
s
=
3
btn2
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -360,7 +360,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_flash_on_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn3
:
FlatButton
=
FlatButton
()
btn3
.
grid
.
column
=
.
Column3
btn3
.
grid
.
column
s
=
4
btn3
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn3
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn3
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -368,21 +368,23 @@ class ViewController: UIViewController {
btn3
.
setImage
(
image
,
forState
:
.
Highlighted
)
view
.
addSubview
(
btn3
)
let
label1
:
MaterialLabel
=
Material
Label
()
let
label1
:
UILabel
=
UI
Label
()
label1
.
text
=
"A"
label1
.
backgroundColor
=
MaterialColor
.
blue
.
base
label1
.
backgroundColor
=
MaterialColor
.
red
.
base
label1
.
grid
.
columns
=
2
view
.
addSubview
(
label1
)
let
label2
:
MaterialLabel
=
MaterialLabel
()
label2
.
text
=
"B"
label2
.
backgroundColor
=
MaterialColor
.
blue
.
base
view
.
grid
.
column
=
.
Column
9
// view.grid.columns =
9
view
.
grid
.
spacing
=
16
view
.
grid
.
contentInset
.
left
=
16
view
.
grid
.
contentInset
.
right
=
16
view
.
grid
.
contentInset
.
top
=
100
view
.
grid
.
contentInset
.
bottom
=
100
view
.
grid
.
views
=
[
btn1
,
btn2
,
btn3
]
view
.
grid
.
views
=
[
btn1
,
btn2
,
label1
,
btn3
]
for
v
in
view
.
grid
.
views
!
{
print
(
v
.
frame
)
...
...
@@ -397,7 +399,7 @@ class ViewController: UIViewController {
private
func
prepareVerticalGridViewExample
()
{
var
image
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn1
:
FlatButton
=
FlatButton
()
btn1
.
grid
.
row
=
.
Row
3
btn1
.
grid
.
row
s
=
3
btn1
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -407,7 +409,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_flash_off_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn2
:
FlatButton
=
FlatButton
()
btn2
.
grid
.
row
=
.
Row
3
btn2
.
grid
.
row
s
=
3
btn2
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -417,7 +419,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_flash_on_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn3
:
FlatButton
=
FlatButton
()
btn3
.
grid
.
row
=
.
Row
3
btn3
.
grid
.
row
s
=
3
btn3
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn3
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn3
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -433,8 +435,8 @@ class ViewController: UIViewController {
label2
.
text
=
"B"
label2
.
backgroundColor
=
MaterialColor
.
blue
.
base
view
.
grid
.
axis
=
.
Vertical
view
.
grid
.
row
=
.
Row
9
view
.
grid
.
axis
.
direction
=
.
Vertical
view
.
grid
.
row
s
=
9
view
.
grid
.
spacing
=
16
view
.
grid
.
contentInset
.
left
=
16
view
.
grid
.
contentInset
.
right
=
16
...
...
Sources/Grid.swift
View file @
50d1b21d
...
...
@@ -30,70 +30,88 @@
import
UIKit
public
enum
GridRow
:
Int
{
case
Row1
=
1
case
Row2
=
2
case
Row3
=
3
case
Row4
=
4
case
Row5
=
5
case
Row6
=
6
case
Row7
=
7
case
Row8
=
8
case
Row9
=
9
case
Row10
=
10
case
Row11
=
11
case
Row12
=
12
}
public
enum
GridColumn
:
Int
{
case
Column1
=
1
case
Column2
=
2
case
Column3
=
3
case
Column4
=
4
case
Column5
=
5
case
Column6
=
6
case
Column7
=
7
case
Column8
=
8
case
Column9
=
9
case
Column10
=
10
case
Column11
=
11
case
Column12
=
12
}
public
enum
GridAxis
{
public
enum
GridAxisDirection
{
case
Horizontal
case
Vertical
}
public
class
Grid
{
/// The row size.
public
var
row
:
GridRow
{
public
class
GridAxis
{
/// Grid reference.
unowned
var
grid
:
Grid
/// Inherit grid rows and columns.
public
var
inherited
:
Bool
=
true
/// The direction the grid layouts its views out.
public
var
direction
:
GridAxisDirection
=
.
Horizontal
/// The rows size.
public
var
rows
:
Int
{
didSet
{
reloadLayout
()
grid
.
reloadLayout
()
}
}
/// The
row
size.
public
var
rowOffset
:
GridRow
?
{
/// The
columns
size.
public
var
columns
:
Int
{
didSet
{
reloadLayout
()
grid
.
reloadLayout
()
}
}
public
init
(
grid
:
Grid
,
rows
:
Int
=
12
,
columns
:
Int
=
12
)
{
self
.
grid
=
grid
self
.
rows
=
rows
self
.
columns
=
columns
}
}
public
class
GridOffset
{
/// Grid reference.
unowned
var
grid
:
Grid
/// The rows size.
public
var
rows
:
Int
{
didSet
{
grid
.
reloadLayout
()
}
}
/// The column size.
public
var
column
:
GridColumn
{
/// The columns size.
public
var
columns
:
Int
{
didSet
{
grid
.
reloadLayout
()
}
}
public
init
(
grid
:
Grid
,
rows
:
Int
=
0
,
columns
:
Int
=
0
)
{
self
.
grid
=
grid
self
.
rows
=
rows
self
.
columns
=
columns
}
}
public
class
Grid
{
/// The rows size.
public
var
rows
:
Int
{
didSet
{
reloadLayout
()
}
}
/// The column size.
public
var
column
Offset
:
GridColumn
?
{
/// The column
s
size.
public
var
column
s
:
Int
{
didSet
{
reloadLayout
()
}
}
/// Offsets for rows and columns.
public
private(set)
var
offset
:
GridOffset
!
/// The axis in which the Grid is laying out its views.
public
private(set)
var
axis
:
GridAxis
!
/// Preset inset value for grid.
public
var
contentInsetPreset
:
MaterialEdgeInsetPreset
=
.
None
{
didSet
{
...
...
@@ -108,20 +126,13 @@ public class Grid {
}
}
/// The space between grid columns.
/// The space between grid columns
s
.
public
var
spacing
:
CGFloat
{
didSet
{
reloadLayout
()
}
}
/// The axis in which the Grid is laying out its views.
public
var
axis
:
GridAxis
=
.
Horizontal
{
didSet
{
reloadLayout
()
}
}
/// An Array of UIButtons.
public
var
views
:
Array
<
UIView
>
?
{
didSet
{
...
...
@@ -129,10 +140,12 @@ public class Grid {
}
}
public
init
(
row
:
GridRow
=
.
Row12
,
column
:
GridColumn
=
.
Column
12
,
spacing
:
CGFloat
=
0
)
{
self
.
row
=
row
self
.
column
=
column
public
init
(
row
s
:
Int
=
12
,
columns
:
Int
=
12
,
spacing
:
CGFloat
=
0
)
{
self
.
row
s
=
rows
self
.
column
s
=
columns
self
.
spacing
=
spacing
self
.
offset
=
GridOffset
(
grid
:
self
)
self
.
axis
=
GridAxis
(
grid
:
self
)
}
/// Reload the button layout.
...
...
@@ -143,13 +156,13 @@ public class Grid {
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
-
1
;
i
<=
l
;
++
i
{
let
view
:
UIView
=
v
[
i
]
if
let
sv
:
UIView
=
view
.
superview
{
let
w
:
CGFloat
=
(
sv
.
bounds
.
width
-
contentInset
.
left
-
contentInset
.
right
+
spacing
)
/
CGFloat
(
column
.
rawValue
)
let
h
:
CGFloat
=
(
sv
.
bounds
.
height
-
contentInset
.
top
-
contentInset
.
bottom
+
spacing
)
/
CGFloat
(
row
.
rawValue
)
let
c
:
Int
=
view
.
grid
.
column
.
rawValue
let
r
:
Int
=
view
.
grid
.
row
.
rawValue
let
co
:
Int
=
nil
==
view
.
grid
.
columnOffset
?
0
:
view
.
grid
.
columnOffset
!.
rawValue
let
ro
:
Int
=
nil
==
view
.
grid
.
rowOffset
?
0
:
view
.
grid
.
rowOffset
!.
rawValue
if
.
Horizontal
==
axis
{
let
w
:
CGFloat
=
(
sv
.
bounds
.
width
-
contentInset
.
left
-
contentInset
.
right
+
spacing
)
/
CGFloat
(
axis
.
inherited
?
columns
:
axis
.
columns
)
let
h
:
CGFloat
=
(
sv
.
bounds
.
height
-
contentInset
.
top
-
contentInset
.
bottom
+
spacing
)
/
CGFloat
(
axis
.
inherited
?
rows
:
axis
.
rows
)
let
c
:
Int
=
view
.
grid
.
column
s
let
r
:
Int
=
view
.
grid
.
row
s
let
co
:
Int
=
view
.
grid
.
offset
.
columns
let
ro
:
Int
=
view
.
grid
.
offset
.
rows
if
.
Horizontal
==
axis
.
direction
{
// View height.
let
vh
:
CGFloat
=
sv
.
bounds
.
height
-
contentInset
.
top
-
contentInset
.
bottom
...
...
@@ -167,7 +180,9 @@ public class Grid {
}
else
{
view
.
frame
=
CGRectMake
(
vl
,
contentInset
.
top
,
vw
,
vh
)
}
}
else
if
.
Vertical
==
axis
{
n
+=
c
+
co
-
1
}
else
if
.
Vertical
==
axis
.
direction
{
// View width.
let
vw
:
CGFloat
=
sv
.
bounds
.
width
-
contentInset
.
left
-
contentInset
.
right
...
...
@@ -184,17 +199,17 @@ public class Grid {
}
else
{
view
.
frame
=
CGRectMake
(
contentInset
.
left
,
vt
,
vw
,
vh
)
}
m
+=
r
+
ro
-
1
}
n
+=
c
+
co
-
1
m
+=
r
+
ro
-
1
}
}
}
}
}
private
func
associatedObject
<
ValueType
:
AnyObject
>
(
base
:
AnyObject
,
key
:
UnsafePointer
<
UInt8
>
,
initialiser
:
()
->
ValueType
)
->
ValueType
{
if
let
associated
=
objc_getAssociatedObject
(
base
,
key
)
as?
ValueType
{
private
func
associatedObject
<
T
:
AnyObject
>
(
base
:
AnyObject
,
key
:
UnsafePointer
<
UInt8
>
,
initialiser
:
()
->
T
)
->
T
{
if
let
associated
:
T
=
objc_getAssociatedObject
(
base
,
key
)
as?
T
{
return
associated
}
...
...
@@ -203,7 +218,7 @@ private func associatedObject<ValueType: AnyObject>(base: AnyObject, key: Unsafe
return
associated
}
private
func
associateObject
<
ValueType
:
AnyObject
>
(
base
:
AnyObject
,
key
:
UnsafePointer
<
UInt8
>
,
value
:
ValueType
)
{
private
func
associateObject
<
T
:
AnyObject
>
(
base
:
AnyObject
,
key
:
UnsafePointer
<
UInt8
>
,
value
:
T
)
{
objc_setAssociatedObject
(
base
,
key
,
value
,
.
OBJC_ASSOCIATION_RETAIN
)
}
...
...
@@ -212,7 +227,9 @@ private var gridKey: UInt8 = 0
public
extension
UIView
{
public
var
grid
:
Grid
{
get
{
return
associatedObject
(
self
,
key
:
&
gridKey
)
{
return
Grid
()
}
return
associatedObject
(
self
,
key
:
&
gridKey
)
{
return
Grid
()
}
}
set
(
value
)
{
associateObject
(
self
,
key
:
&
gridKey
,
value
:
value
)
...
...
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