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
55d70ff5
Commit
55d70ff5
authored
Feb 10, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GridView working
parent
acf28e9a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
134 deletions
+58
-134
Examples/Programmatic/GridView/GridView/ViewController.swift
+12
-6
Sources/GridView.swift
+34
-8
Sources/MaterialButton.swift
+4
-1
Sources/MaterialLabel.swift
+4
-118
Sources/MaterialView.swift
+4
-1
No files found.
Examples/Programmatic/GridView/GridView/ViewController.swift
View file @
55d70ff5
...
...
@@ -53,6 +53,7 @@ class ViewController: UIViewController {
private
func
prepareHorizontalGridViewExample
()
{
var
image
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn1
:
FlatButton
=
FlatButton
()
btn1
.
grid
=
.
Grid2
btn1
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn1
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -61,6 +62,7 @@ class ViewController: UIViewController {
image
=
UIImage
(
named
:
"ic_flash_off_white"
)?
.
imageWithRenderingMode
(
.
AlwaysTemplate
)
let
btn2
:
FlatButton
=
FlatButton
()
// btn2.grid = .Grid3
btn2
.
pulseColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
tintColor
=
MaterialColor
.
blueGrey
.
darken4
btn2
.
backgroundColor
=
MaterialColor
.
grey
.
lighten3
...
...
@@ -75,21 +77,25 @@ class ViewController: UIViewController {
btn3
.
setImage
(
image
,
forState
:
.
Normal
)
btn3
.
setImage
(
image
,
forState
:
.
Highlighted
)
let
label1
:
UILabel
=
UI
Label
()
let
label1
:
MaterialLabel
=
Material
Label
()
label1
.
text
=
"A"
label1
.
backgroundColor
=
MaterialColor
.
blue
.
base
let
label2
:
UILabel
=
UI
Label
()
let
label2
:
MaterialLabel
=
Material
Label
()
label2
.
text
=
"B"
label2
.
grid
=
.
Grid2
label2
.
backgroundColor
=
MaterialColor
.
blue
.
base
let
gridView
:
GridView
=
GridView
(
frame
:
CGRectMake
(
0
,
100
,
view
.
bounds
.
width
,
40
)
)
let
gridView
:
GridView
=
GridView
()
gridView
.
grid
=
.
Grid5
gridView
.
spacing
=
16
gridView
.
views
=
[
btn1
,
btn2
,
btn3
,
label1
,
label2
]
gridView
.
spacing
=
32
// gridView.unifiedHeight = 40
gridView
.
views
=
[
btn1
,
btn2
,
label2
]
view
.
addSubview
(
gridView
)
gridView
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromTop
(
view
,
child
:
gridView
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
gridView
)
}
}
Sources/GridView.swift
View file @
55d70ff5
...
...
@@ -31,6 +31,7 @@
import
UIKit
public
enum
Grid
:
Int
{
case
Grid1
=
1
case
Grid2
=
2
case
Grid3
=
3
case
Grid4
=
4
...
...
@@ -49,9 +50,21 @@ public enum GridLayout {
case
Vertical
}
public
protocol
GridCell
{
/// Grid spacing.
var
grid
:
Grid
{
get
set
}
}
public
class
GridView
:
MaterialView
{
/// A single height for all views.
public
var
unifiedHeight
:
CGFloat
=
0
{
didSet
{
reloadLayout
()
}
}
/// The grid size.
public
var
grid
:
Grid
{
public
override
var
grid
:
Grid
{
didSet
{
reloadLayout
()
}
...
...
@@ -72,7 +85,7 @@ public class GridView : MaterialView {
}
/// An Array of UIButtons.
public
var
views
:
Array
<
UIView
>
?
{
public
var
views
:
Array
<
GridCell
>
?
{
didSet
{
reloadLayout
()
}
...
...
@@ -83,15 +96,20 @@ public class GridView : MaterialView {
}
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
grid
=
.
Grid12
spacing
=
0
super
.
init
(
coder
:
aDecoder
)
grid
=
.
Grid12
}
public
override
init
(
frame
:
CGRect
)
{
grid
=
.
Grid12
spacing
=
0
super
.
init
(
frame
:
frame
)
grid
=
.
Grid12
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
reloadLayout
()
}
/// Reload the button layout.
...
...
@@ -100,12 +118,20 @@ public class GridView : MaterialView {
v
.
removeFromSuperview
()
}
let
w
:
CGFloat
=
(
width
-
spacing
)
/
CGFloat
(
grid
.
rawValue
)
if
let
v
:
Array
<
UIView
>
=
views
{
let
g
:
Int
=
grid
.
rawValue
let
w
:
CGFloat
=
(
width
-
spacing
)
/
CGFloat
(
g
)
if
let
v
:
Array
<
GridCell
>
=
views
{
var
n
:
Int
=
0
for
var
i
:
Int
=
0
,
l
:
Int
=
v
.
count
;
i
<
l
;
++
i
{
let
view
:
UIView
=
v
[
i
]
view
.
frame
=
CGRectMake
(
CGFloat
(
i
)
*
w
+
spacing
,
0
,
w
-
spacing
,
height
)
let
cell
:
GridCell
=
v
[
i
]
let
view
:
UIView
=
cell
as!
UIView
let
m
:
Int
=
cell
.
grid
.
rawValue
if
.
Horizontal
==
layout
{
view
.
frame
=
CGRectMake
(
CGFloat
(
i
+
n
)
*
w
+
spacing
,
0
,
(
w
*
CGFloat
(
m
))
-
spacing
,
0
<
unifiedHeight
?
unifiedHeight
:
view
.
intrinsicContentSize
()
.
height
)
}
view
.
removeFromSuperview
()
addSubview
(
view
)
n
+=
m
-
1
}
}
}
...
...
Sources/MaterialButton.swift
View file @
55d70ff5
...
...
@@ -31,7 +31,10 @@
import
UIKit
@objc(MaterialButton)
public
class
MaterialButton
:
UIButton
{
public
class
MaterialButton
:
UIButton
,
GridCell
{
/// Grid space.
public
var
grid
:
Grid
=
.
Grid1
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
...
...
Sources/MaterialLabel.swift
View file @
55d70ff5
...
...
@@ -30,122 +30,7 @@
import
UIKit
public
class
MaterialLabel
:
UILabel
{
/**
:name: layerClass
*/
public
override
class
func
layerClass
()
->
AnyClass
{
return
MaterialTextLayer
.
self
}
/**
:name: textLayer
*/
public
var
textLayer
:
MaterialTextLayer
{
return
layer
as!
MaterialTextLayer
}
/**
:name: text
*/
public
override
var
text
:
String
?
{
didSet
{
textLayer
.
text
=
text
}
}
/**
:name: textColor
*/
public
override
var
textColor
:
UIColor
?
{
didSet
{
textLayer
.
textColor
=
textColor
}
}
/**
:name: font
*/
public
override
var
font
:
UIFont
!
{
didSet
{
textLayer
.
fontType
=
font
}
}
/**
:name: textAlignment
*/
public
override
var
textAlignment
:
NSTextAlignment
{
didSet
{
textLayer
.
textAlignment
=
textAlignment
}
}
/**
:name: wrapped
*/
public
var
wrapped
:
Bool
{
didSet
{
textLayer
.
wrapped
=
wrapped
}
}
/**
:name: contentsScale
*/
public
var
contentsScale
:
CGFloat
{
didSet
{
textLayer
.
contentsScale
=
contentsScale
}
}
/**
:name: lineBreakMode
*/
public
override
var
lineBreakMode
:
NSLineBreakMode
{
didSet
{
textLayer
.
lineBreakMode
=
lineBreakMode
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
wrapped
=
true
contentsScale
=
UIScreen
.
mainScreen
()
.
scale
super
.
init
(
coder
:
aDecoder
)
}
/**
:name: init
*/
public
override
init
(
frame
:
CGRect
)
{
wrapped
=
true
contentsScale
=
UIScreen
.
mainScreen
()
.
scale
super
.
init
(
frame
:
frame
)
prepareView
()
}
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
prepareView
()
}
/**
:name: stringSize
*/
public
func
stringSize
(
constrainedToWidth
width
:
Double
)
->
CGSize
{
return
textLayer
.
stringSize
(
constrainedToWidth
:
width
)
}
/**
:name: prepareView
*/
public
func
prepareView
()
{
textAlignment
=
.
Left
}
public
class
MaterialLabel
:
UILabel
,
GridCell
{
/// Grid space.
public
var
grid
:
Grid
=
.
Grid1
}
\ No newline at end of file
Sources/MaterialView.swift
View file @
55d70ff5
...
...
@@ -31,7 +31,10 @@
import
UIKit
@objc(MaterialView)
public
class
MaterialView
:
UIView
{
public
class
MaterialView
:
UIView
,
GridCell
{
/// Grid space.
public
var
grid
:
Grid
=
.
Grid1
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
...
...
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