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
b52dc86e
Commit
b52dc86e
authored
Oct 09, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated MaterialButton to use MaterialLayer
parent
6850033a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
76 deletions
+51
-76
Source/MaterialButton.swift
+42
-63
Source/MaterialLayer.swift
+6
-3
Source/MaterialView.swift
+3
-10
No files found.
Source/MaterialButton.swift
View file @
b52dc86e
...
...
@@ -102,11 +102,23 @@ public class MaterialButton : UIButton {
}
/**
:name: masksToBounds
*/
public
var
masksToBounds
:
Bool
{
get
{
return
materialLayer
.
masksToBounds
}
set
(
value
)
{
materialLayer
.
masksToBounds
=
value
}
}
/**
:name: backgroundColor
*/
public
override
var
backgroundColor
:
UIColor
?
{
didSet
{
l
ayer
.
backgroundColor
=
backgroundColor
?
.
CGColor
materialL
ayer
.
backgroundColor
=
backgroundColor
?
.
CGColor
}
}
...
...
@@ -115,10 +127,10 @@ public class MaterialButton : UIButton {
*/
public
var
x
:
CGFloat
{
get
{
return
frame
.
origin
.
x
return
materialLayer
.
x
}
set
(
value
)
{
frame
.
origin
.
x
=
value
materialLayer
.
x
=
value
}
}
...
...
@@ -127,10 +139,10 @@ public class MaterialButton : UIButton {
*/
public
var
y
:
CGFloat
{
get
{
return
frame
.
origin
.
y
return
materialLayer
.
y
}
set
(
value
)
{
frame
.
origin
.
y
=
value
materialLayer
.
y
=
value
}
}
...
...
@@ -139,13 +151,10 @@ public class MaterialButton : UIButton {
*/
public
var
width
:
CGFloat
{
get
{
return
frame
.
size
.
width
return
materialLayer
.
width
}
set
(
value
)
{
frame
.
size
.
width
=
value
if
.
None
!=
shape
{
frame
.
size
.
height
=
value
}
materialLayer
.
width
=
value
}
}
...
...
@@ -154,13 +163,10 @@ public class MaterialButton : UIButton {
*/
public
var
height
:
CGFloat
{
get
{
return
frame
.
size
.
height
return
materialLayer
.
height
}
set
(
value
)
{
frame
.
size
.
height
=
value
if
.
None
!=
shape
{
frame
.
size
.
width
=
value
}
materialLayer
.
height
=
value
}
}
...
...
@@ -210,28 +216,11 @@ public class MaterialButton : UIButton {
}
/**
:name: masksToBounds
*/
public
var
masksToBounds
:
Bool
{
get
{
return
visualLayer
.
masksToBounds
}
set
(
value
)
{
visualLayer
.
masksToBounds
=
value
}
}
/**
:name: cornerRadius
*/
public
var
cornerRadius
:
MaterialRadius
?
{
public
var
cornerRadius
:
MaterialRadius
{
didSet
{
if
let
v
:
MaterialRadius
=
cornerRadius
{
layer
.
cornerRadius
=
MaterialRadiusToValue
(
v
)
if
.
Circle
==
shape
{
shape
=
.
None
}
}
materialLayer
.
cornerRadius
=
MaterialRadiusToValue
(
cornerRadius
)
}
}
...
...
@@ -242,9 +231,9 @@ public class MaterialButton : UIButton {
didSet
{
if
.
None
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
width
=
height
}
else
{
frame
.
size
.
height
=
width
height
=
width
}
}
}
...
...
@@ -255,7 +244,7 @@ public class MaterialButton : UIButton {
*/
public
var
borderWidth
:
MaterialBorder
{
didSet
{
l
ayer
.
borderWidth
=
MaterialBorderToValue
(
borderWidth
)
materialL
ayer
.
borderWidth
=
MaterialBorderToValue
(
borderWidth
)
}
}
...
...
@@ -264,7 +253,7 @@ public class MaterialButton : UIButton {
*/
public
var
borderColor
:
UIColor
?
{
didSet
{
l
ayer
.
borderColor
=
borderColor
?
.
CGColor
materialL
ayer
.
borderColor
=
borderColor
?
.
CGColor
}
}
...
...
@@ -322,6 +311,7 @@ public class MaterialButton : UIButton {
shadowDepth
=
.
None
shape
=
.
None
contentInsets
=
.
None
cornerRadius
=
.
None
super
.
init
(
coder
:
aDecoder
)
}
...
...
@@ -333,26 +323,26 @@ public class MaterialButton : UIButton {
shadowDepth
=
.
None
shape
=
.
None
contentInsets
=
.
None
cornerRadius
=
.
None
super
.
init
(
frame
:
frame
)
prepareView
()
}
/**
:name:
init
:name:
layoutSublayersOfLayer
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
public
override
func
layoutSublayersOfLayer
(
layer
:
CALayer
)
{
super
.
layoutSublayersOfLayer
(
layer
)
if
self
.
layer
==
layer
{
prepareShape
()
}
}
/**
:name:
layoutSubviews
:name:
init
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
prepareShape
()
visualLayer
.
frame
=
bounds
visualLayer
.
position
=
CGPointMake
(
width
/
2
,
height
/
2
)
visualLayer
.
cornerRadius
=
layer
.
cornerRadius
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectNull
)
}
/**
...
...
@@ -424,24 +414,13 @@ public class MaterialButton : UIButton {
}
/**
:name: actionForLayer
*/
public
override
func
actionForLayer
(
layer
:
CALayer
,
forKey
event
:
String
)
->
CAAction
?
{
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
}
/**
:name: prepareView
*/
public
func
prepareView
()
{
// visualLayer
visualLayer
.
zPosition
=
-
1
layer
.
addSublayer
(
visualLayer
)
// pulseLayer
pulseLayer
.
hidden
=
true
pulseLayer
.
zPosition
=
1
visualLayer
.
addSublayer
(
pulseLayer
)
materialLayer
.
visualLayer
.
addSublayer
(
pulseLayer
)
}
//
...
...
@@ -449,7 +428,7 @@ public class MaterialButton : UIButton {
//
internal
func
prepareShape
()
{
if
.
Circle
==
shape
{
l
ayer
.
cornerRadius
=
width
/
2
materialL
ayer
.
cornerRadius
=
width
/
2
}
}
...
...
Source/MaterialLayer.swift
View file @
b52dc86e
...
...
@@ -289,6 +289,9 @@ public class MaterialLayer : CAShapeLayer {
}
animationDelegate
?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
removeAnimationForKey
(
a
.
keyPath
!
)
if
"cornerRadius"
==
a
.
keyPath
{
visualLayer
.
addAnimation
(
a
,
forKey
:
"cornerRadius"
)
}
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
...
...
@@ -301,9 +304,9 @@ public class MaterialLayer : CAShapeLayer {
*/
public
func
prepareLayer
()
{
// visualLayer
masksToBounds
=
true
visualLayer
.
zPosition
=
-
1
addSublayer
(
visualLayer
)
//
masksToBounds = true
//
visualLayer.zPosition = -1
//
addSublayer(visualLayer)
}
//
...
...
Source/MaterialView.swift
View file @
b52dc86e
...
...
@@ -210,10 +210,10 @@ public class MaterialView : UIView {
*/
public
var
shadowRadius
:
CGFloat
{
get
{
return
materialL
ayer
.
shadowRadius
return
l
ayer
.
shadowRadius
}
set
(
value
)
{
materialL
ayer
.
shadowRadius
=
value
l
ayer
.
shadowRadius
=
value
}
}
...
...
@@ -338,13 +338,6 @@ public class MaterialView : UIView {
}
/**
:name: actionForLayer
*/
public
override
func
actionForLayer
(
layer
:
CALayer
,
forKey
event
:
String
)
->
CAAction
?
{
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
}
/**
:name: animation
*/
public
func
animation
(
animation
:
CAAnimation
)
{
...
...
@@ -375,7 +368,7 @@ public class MaterialView : UIView {
//
internal
func
prepareShape
()
{
if
.
Circle
==
shape
{
l
ayer
.
cornerRadius
=
width
/
2
materialL
ayer
.
cornerRadius
=
width
/
2
}
}
}
...
...
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