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
459aef04
Commit
459aef04
authored
Aug 27, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-17: updated button interface
parent
ae77e281
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
65 deletions
+64
-65
Source/AddFabButton.swift
+7
-0
Source/FabButton.swift
+4
-3
Source/FlatButton.swift
+14
-2
Source/MaterialButton.swift
+32
-33
Source/RaisedButton.swift
+7
-27
No files found.
Source/AddFabButton.swift
View file @
459aef04
...
@@ -24,7 +24,14 @@ public class AddFabButton : FabButton {
...
@@ -24,7 +24,14 @@ public class AddFabButton : FabButton {
*/
*/
public
var
lineWidth
:
CGFloat
=
2
public
var
lineWidth
:
CGFloat
=
2
//
// :name: verticalLine
//
private
var
verticalLine
:
UIView
!
private
var
verticalLine
:
UIView
!
//
// :name: horizontalLine
//
private
var
horizontalLine
:
UIView
!
private
var
horizontalLine
:
UIView
!
//
//
...
...
Source/FabButton.swift
View file @
459aef04
...
@@ -24,16 +24,17 @@ public class FabButton : MaterialButton {
...
@@ -24,16 +24,17 @@ public class FabButton : MaterialButton {
//
//
internal
override
func
prepareButton
()
{
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
super
.
prepareButton
()
prepareShadow
()
backgroundColor
=
.
redColor
()
backgroundColor
=
.
redColor
()
pulseColor
=
.
whiteColor
()
pulseColor
=
.
whiteColor
()
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
}
}
//
//
// :name: pulse
Touches
// :name: pulse
Began
//
//
internal
override
func
pulse
Touches
(
touches
:
Set
<
NSObject
>
)
{
internal
override
func
pulse
Began
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
pulse
Touches
(
touches
)
super
.
pulse
Began
(
touches
,
withEvent
:
event
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
3
,
3
)
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
3
,
3
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.1
,
1.1
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.1
,
1.1
)
...
...
Source/FlatButton.swift
View file @
459aef04
...
@@ -18,14 +18,26 @@
...
@@ -18,14 +18,26 @@
import
UIKit
import
UIKit
public
class
FlatButton
:
Raised
Button
{
public
class
FlatButton
:
Material
Button
{
//
//
// :name: prepareButton
// :name: prepareButton
//
//
internal
override
func
prepareButton
()
{
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
super
.
prepareButton
()
setTitleColor
(
UIColor
.
purpleColor
(),
forState
:
.
Normal
)
pulseColor
=
.
purpleColor
()
backgroundColor
=
.
clearColor
()
backgroundColor
=
.
clearColor
()
pulseColor
=
.
whiteColor
()
backgroundColorView
.
layer
.
cornerRadius
=
3
backgroundColorView
.
layer
.
cornerRadius
=
3
}
}
//
// :name: pulseBegan
//
internal
override
func
pulseBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
pulseBegan
(
touches
,
withEvent
:
event
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
})
}
}
}
Source/MaterialButton.swift
View file @
459aef04
...
@@ -71,7 +71,7 @@ public class MaterialButton : UIButton {
...
@@ -71,7 +71,7 @@ public class MaterialButton : UIButton {
*/
*/
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
pulse
Touches
(
touches
)
pulse
Began
(
touches
,
withEvent
:
event
)
}
}
/**
/**
...
@@ -80,16 +80,16 @@ public class MaterialButton : UIButton {
...
@@ -80,16 +80,16 @@ public class MaterialButton : UIButton {
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
shrink
()
shrink
()
removePulse
(
)
pulseEnded
(
touches
,
withEvent
:
event
)
}
}
/**
/**
:name: touchesCancelled
:name: touchesCancelled
*/
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
!
)
{
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>
!
,
withEvent
event
:
UIEvent
!
)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
shrink
()
shrink
()
removePulse
(
)
pulseEnded
(
touches
,
withEvent
:
event
)
}
}
/**
/**
...
@@ -97,7 +97,6 @@ public class MaterialButton : UIButton {
...
@@ -97,7 +97,6 @@ public class MaterialButton : UIButton {
*/
*/
final
public
override
func
drawRect
(
rect
:
CGRect
)
{
final
public
override
func
drawRect
(
rect
:
CGRect
)
{
prepareContext
(
rect
)
prepareContext
(
rect
)
prepareShadow
()
prepareButton
()
prepareButton
()
prepareBackgroundColorView
()
prepareBackgroundColorView
()
}
}
...
@@ -110,20 +109,44 @@ public class MaterialButton : UIButton {
...
@@ -110,20 +109,44 @@ public class MaterialButton : UIButton {
}
}
//
//
// :name: pulse
Touches
// :name: pulse
Began
//
//
internal
func
pulse
Touches
(
touches
:
Set
<
NSObject
>
)
{
internal
func
pulse
Began
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
let
touch
=
touches
.
first
as!
UITouch
let
touch
=
touches
.
first
as!
UITouch
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
.
height
,
bounds
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2
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
!
)
}
}
//
//
// :name: pulseEnded
//
internal
func
pulseEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
_
in
self
.
pulseView
?
.
alpha
=
0
}
)
{
_
in
self
.
pulseView
?
.
removeFromSuperview
()
self
.
pulseView
=
nil
}
}
//
// :name: prepareShadow
//
internal
func
prepareShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
//
// :name: prepareBackgroundColorView
// :name: prepareBackgroundColorView
//
//
// We need this view so we can use the masksToBounds
// We need this view so we can use the masksToBounds
...
@@ -143,16 +166,6 @@ public class MaterialButton : UIButton {
...
@@ -143,16 +166,6 @@ public class MaterialButton : UIButton {
}
}
//
//
// :name: prepareShadow
//
private
func
prepareShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
//
// :name: prepareContext
// :name: prepareContext
//
//
private
func
prepareContext
(
rect
:
CGRect
)
{
private
func
prepareContext
(
rect
:
CGRect
)
{
...
@@ -179,18 +192,4 @@ public class MaterialButton : UIButton {
...
@@ -179,18 +192,4 @@ public class MaterialButton : UIButton {
completion
:
nil
completion
:
nil
)
)
}
}
//
// :name: removePulse
//
private
func
removePulse
()
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
_
in
self
.
pulseView
?
.
alpha
=
0
}
)
{
_
in
self
.
pulseView
?
.
removeFromSuperview
()
self
.
pulseView
=
nil
}
}
}
}
Source/RaisedButton.swift
View file @
459aef04
...
@@ -19,47 +19,27 @@
...
@@ -19,47 +19,27 @@
import
UIKit
import
UIKit
public
class
RaisedButton
:
MaterialButton
{
public
class
RaisedButton
:
MaterialButton
{
/**
:name: pulseTitleColor
*/
public
var
pulseTitleColor
:
UIColor
?
/**
:name: titleColor
*/
public
var
titleColor
:
UIColor
?
{
didSet
{
setTitleColor
(
titleColor
,
forState
:
.
Normal
)
}
}
//
//
// :name: prepareButton
// :name: prepareButton
//
//
internal
override
func
prepareButton
()
{
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
super
.
prepareButton
()
prepareShadow
()
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
pulseColor
=
.
whiteColor
()
pulseColor
=
.
whiteColor
()
backgroundColor
=
.
purpleColor
()
backgroundColorView
.
layer
.
cornerRadius
=
3
backgroundColorView
.
layer
.
cornerRadius
=
3
}
}
//
//
// :name: pulse
Touches
// :name: pulse
Began
//
//
internal
override
func
pulse
Touches
(
touches
:
Set
<
NSObject
>
)
{
internal
override
func
pulse
Began
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
pulse
Touches
(
touches
)
super
.
pulse
Began
(
touches
,
withEvent
:
event
)
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.05
,
1.1
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
if
let
c
=
self
.
pulseTitleColor
{
})
self
.
setTitleColor
(
c
,
forState
:
.
Normal
)
}
})
{
_
in
if
let
c
=
self
.
titleColor
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
setTitleColor
(
c
,
forState
:
.
Normal
)
})
}
}
}
}
}
}
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