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
605728de
Commit
605728de
authored
Aug 27, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
progressive cleanup
parent
e0f8187c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
29 deletions
+66
-29
Source/AddFabButton.swift
+2
-2
Source/FabButton.swift
+10
-2
Source/FlatButton.swift
+10
-2
Source/MaterialButton.swift
+34
-21
Source/RaisedButton.swift
+10
-2
No files found.
Source/AddFabButton.swift
View file @
605728de
...
@@ -35,7 +35,7 @@ public class AddFabButton : FabButton {
...
@@ -35,7 +35,7 @@ public class AddFabButton : FabButton {
// :name: prepareVerticalLine
// :name: prepareVerticalLine
//
//
private
func
prepareVerticalLine
()
{
private
func
prepareVerticalLine
()
{
verticalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
lineWidth
,
CGRectGetHeight
(
backgroundColorView
.
frame
)
/
3
.0
))
verticalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
lineWidth
,
CGRectGetHeight
(
backgroundColorView
.
frame
)
/
3
))
verticalLine
.
backgroundColor
=
.
whiteColor
()
verticalLine
.
backgroundColor
=
.
whiteColor
()
verticalLine
.
center
=
backgroundColorView
.
center
verticalLine
.
center
=
backgroundColorView
.
center
backgroundColorView
.
addSubview
(
verticalLine
)
backgroundColorView
.
addSubview
(
verticalLine
)
...
@@ -45,7 +45,7 @@ public class AddFabButton : FabButton {
...
@@ -45,7 +45,7 @@ public class AddFabButton : FabButton {
// :name: prepareHorizontalLine
// :name: prepareHorizontalLine
//
//
private
func
prepareHorizontalLine
()
{
private
func
prepareHorizontalLine
()
{
horizontalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
CGRectGetWidth
(
backgroundColorView
.
frame
)
/
3
.0
,
lineWidth
))
horizontalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
CGRectGetWidth
(
backgroundColorView
.
frame
)
/
3
,
lineWidth
))
horizontalLine
.
backgroundColor
=
.
whiteColor
()
horizontalLine
.
backgroundColor
=
.
whiteColor
()
horizontalLine
.
center
=
backgroundColorView
.
center
horizontalLine
.
center
=
backgroundColorView
.
center
backgroundColorView
.
addSubview
(
horizontalLine
)
backgroundColorView
.
addSubview
(
horizontalLine
)
...
...
Source/FabButton.swift
View file @
605728de
...
@@ -22,7 +22,7 @@ public class FabButton : MaterialButton {
...
@@ -22,7 +22,7 @@ public class FabButton : MaterialButton {
/**
/**
:name: lineWidth
:name: lineWidth
*/
*/
public
var
lineWidth
:
CGFloat
=
2
.0
public
var
lineWidth
:
CGFloat
=
2
//
//
// :name: prepareButton
// :name: prepareButton
...
@@ -34,6 +34,14 @@ public class FabButton : MaterialButton {
...
@@ -34,6 +34,14 @@ public class FabButton : MaterialButton {
}
}
//
//
// :name: prepareBackgroundColorView
//
internal
override
func
prepareBackgroundColorView
()
{
super
.
prepareBackgroundColorView
()
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
}
//
// :name: pulseTouches
// :name: pulseTouches
//
//
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
...
@@ -42,7 +50,7 @@ public class FabButton : MaterialButton {
...
@@ -42,7 +50,7 @@ public class FabButton : MaterialButton {
let
touchLocation
=
touch
.
locationInView
(
self
)
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
bounds
.
width
,
bounds
.
height
)
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
bounds
.
width
,
bounds
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2
.0
pulseView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2
pulseView
!.
center
=
touchLocation
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
pulseView
!.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
.
addSubview
(
pulseView
!
)
backgroundColorView
.
addSubview
(
pulseView
!
)
...
...
Source/FlatButton.swift
View file @
605728de
...
@@ -33,6 +33,14 @@ public class FlatButton : MaterialButton {
...
@@ -33,6 +33,14 @@ public class FlatButton : MaterialButton {
}
}
//
//
// :name: prepareBackgroundColorView
//
internal
override
func
prepareBackgroundColorView
()
{
super
.
prepareBackgroundColorView
()
backgroundColorView
.
layer
.
cornerRadius
=
3
}
//
// :name: pulseTouches
// :name: pulseTouches
//
//
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
...
@@ -41,13 +49,13 @@ public class FlatButton : MaterialButton {
...
@@ -41,13 +49,13 @@ public class FlatButton : MaterialButton {
let
touchLocation
=
touch
.
locationInView
(
self
)
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2
.0
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2
pulseView
!.
center
=
touchLocation
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
.
addSubview
(
pulseView
!
)
backgroundColorView
.
addSubview
(
pulseView
!
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1
.0
5
,
1.1
)
self
.
transform
=
CGAffineTransformMakeScale
(
15
,
1.1
)
self
.
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
self
.
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
})
})
}
}
...
...
Source/MaterialButton.swift
View file @
605728de
...
@@ -19,10 +19,24 @@
...
@@ -19,10 +19,24 @@
import
UIKit
import
UIKit
public
class
MaterialButton
:
UIButton
{
public
class
MaterialButton
:
UIButton
{
//
// :name: backgroundColorView
//
internal
lazy
var
backgroundColorView
:
UIView
=
UIView
()
internal
lazy
var
backgroundColorView
:
UIView
=
UIView
()
//
// :name: pulseView
//
internal
var
pulseView
:
UIView
?
internal
var
pulseView
:
UIView
?
/**
:name: color
*/
public
var
color
:
UIColor
?
public
var
color
:
UIColor
?
/**
:name: pulseColor
*/
public
var
pulseColor
:
UIColor
?
public
var
pulseColor
:
UIColor
?
/**
/**
...
@@ -95,16 +109,29 @@ public class MaterialButton : UIButton {
...
@@ -95,16 +109,29 @@ public class MaterialButton : UIButton {
internal
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{}
internal
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{}
//
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
internal
func
prepareBackgroundColorView
()
{
backgroundColorView
.
frame
=
bounds
backgroundColorView
.
backgroundColor
=
color
backgroundColorView
.
layer
.
masksToBounds
=
true
backgroundColorView
.
userInteractionEnabled
=
false
insertSubview
(
backgroundColorView
,
atIndex
:
0
)
}
//
// :name: prepareView
// :name: prepareView
//
//
internal
func
prepareView
()
{
private
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
}
}
//
//
// :name: prepareShadow
// :name: prepareShadow
//
//
internal
func
prepareShadow
()
{
private
func
prepareShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowOpacity
=
0.5
...
@@ -114,7 +141,7 @@ public class MaterialButton : UIButton {
...
@@ -114,7 +141,7 @@ public class MaterialButton : UIButton {
//
//
// :name: prepareContext
// :name: prepareContext
//
//
internal
func
prepareContext
(
rect
:
CGRect
)
{
private
func
prepareContext
(
rect
:
CGRect
)
{
let
context
=
UIGraphicsGetCurrentContext
()
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextSaveGState
(
context
);
CGContextAddEllipseInRect
(
context
,
rect
)
CGContextAddEllipseInRect
(
context
,
rect
)
...
@@ -124,25 +151,11 @@ public class MaterialButton : UIButton {
...
@@ -124,25 +151,11 @@ public class MaterialButton : UIButton {
}
}
//
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
internal
func
prepareBackgroundColorView
()
{
backgroundColorView
.
frame
=
bounds
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2.0
backgroundColorView
.
backgroundColor
=
color
backgroundColorView
.
layer
.
masksToBounds
=
true
backgroundColorView
.
userInteractionEnabled
=
false
insertSubview
(
backgroundColorView
,
atIndex
:
0
)
}
//
// :name: shrink
// :name: shrink
//
//
internal
func
shrink
()
{
private
func
shrink
()
{
UIView
.
animateWithDuration
(
0.3
,
UIView
.
animateWithDuration
(
0.3
,
delay
:
0
.0
,
delay
:
0
,
usingSpringWithDamping
:
0.2
,
usingSpringWithDamping
:
0.2
,
initialSpringVelocity
:
10
,
initialSpringVelocity
:
10
,
options
:
nil
,
options
:
nil
,
...
@@ -156,10 +169,10 @@ public class MaterialButton : UIButton {
...
@@ -156,10 +169,10 @@ public class MaterialButton : UIButton {
//
//
// :name: removePulse
// :name: removePulse
//
//
internal
func
removePulse
()
{
private
func
removePulse
()
{
UIView
.
animateWithDuration
(
0.3
,
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
_
in
animations
:
{
_
in
self
.
pulseView
?
.
alpha
=
0
.0
self
.
pulseView
?
.
alpha
=
0
}
}
)
{
_
in
)
{
_
in
self
.
pulseView
?
.
removeFromSuperview
()
self
.
pulseView
?
.
removeFromSuperview
()
...
...
Source/RaisedButton.swift
View file @
605728de
...
@@ -29,6 +29,14 @@ public class RaisedButton : MaterialButton {
...
@@ -29,6 +29,14 @@ public class RaisedButton : MaterialButton {
}
}
//
//
// :name: prepareBackgroundColorView
//
internal
override
func
prepareBackgroundColorView
()
{
super
.
prepareBackgroundColorView
()
backgroundColorView
.
layer
.
cornerRadius
=
3
}
//
// :name: pulseTouches
// :name: pulseTouches
//
//
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
...
@@ -37,14 +45,14 @@ public class RaisedButton : MaterialButton {
...
@@ -37,14 +45,14 @@ public class RaisedButton : MaterialButton {
let
touchLocation
=
touch
.
locationInView
(
self
)
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2
.0
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2
pulseView
!.
center
=
touchLocation
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
.
addSubview
(
pulseView
!
)
backgroundColorView
.
addSubview
(
pulseView
!
)
UIView
.
animateWithDuration
(
0.3
,
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1
.0
5
,
1.1
)
self
.
transform
=
CGAffineTransformMakeScale
(
15
,
1.1
)
},
},
completion
:
nil
completion
:
nil
)
)
...
...
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