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
62eb6c6d
Commit
62eb6c6d
authored
Aug 27, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14 from GraphKit/development
Development
parents
493444cf
1e46d9c1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
296 additions
and
342 deletions
+296
-342
MaterialKit.xcodeproj/project.pbxproj
+4
-0
Source/AddFabButton.swift
+53
-0
Source/FabButton.swift
+21
-133
Source/FlatButton.swift
+25
-99
Source/MaterialButton.swift
+167
-4
Source/RaisedButton.swift
+26
-106
Source/SideNavController.swift
+0
-0
No files found.
MaterialKit.xcodeproj/project.pbxproj
View file @
62eb6c6d
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
963832851B89070E0015F710
/* CapturePreview.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9638325F1B88E5BF0015F710
/* CapturePreview.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
963832851B89070E0015F710
/* CapturePreview.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9638325F1B88E5BF0015F710
/* CapturePreview.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
963832881B8908180015F710
/* Layout.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832871B8908180015F710
/* Layout.swift */
;
};
963832881B8908180015F710
/* Layout.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832871B8908180015F710
/* Layout.swift */
;
};
963832891B89097D0015F710
/* Layout.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832871B8908180015F710
/* Layout.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
963832891B89097D0015F710
/* Layout.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832871B8908180015F710
/* Layout.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9638329E1B8EC34D0015F710
/* AddFabButton.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9638329D1B8EC34D0015F710
/* AddFabButton.swift */
;
};
9A94D0F91B895C8C00F586A5
/* Roboto.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38531B89559900FE6B2D
/* Roboto.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9A94D0F91B895C8C00F586A5
/* Roboto.swift in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38531B89559900FE6B2D
/* Roboto.swift */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9A94D0FA1B895EA500F586A5
/* LICENSE in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832631B88E5BF0015F710
/* LICENSE */
;
};
9A94D0FA1B895EA500F586A5
/* LICENSE in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
963832631B88E5BF0015F710
/* LICENSE */
;
};
9A94D0FB1B895EA500F586A5
/* Roboto-Regular.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38591B8956E300FE6B2D
/* Roboto-Regular.ttf */
;
};
9A94D0FB1B895EA500F586A5
/* Roboto-Regular.ttf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9AAC38591B8956E300FE6B2D
/* Roboto-Regular.ttf */
;
};
...
@@ -73,6 +74,7 @@
...
@@ -73,6 +74,7 @@
963832671B88E5BF0015F710
/* TextStorage.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
TextStorage.swift
;
sourceTree
=
"<group>"
;
};
963832671B88E5BF0015F710
/* TextStorage.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
TextStorage.swift
;
sourceTree
=
"<group>"
;
};
963832681B88E5BF0015F710
/* TextView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
TextView.swift
;
sourceTree
=
"<group>"
;
};
963832681B88E5BF0015F710
/* TextView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
TextView.swift
;
sourceTree
=
"<group>"
;
};
963832871B8908180015F710
/* Layout.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Layout.swift
;
sourceTree
=
"<group>"
;
};
963832871B8908180015F710
/* Layout.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
Layout.swift
;
sourceTree
=
"<group>"
;
};
9638329D1B8EC34D0015F710
/* AddFabButton.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AddFabButton.swift
;
sourceTree
=
"<group>"
;
};
9A94D1081B8A3F5100F586A5
/* MaterialPulseView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialPulseView.swift
;
sourceTree
=
"<group>"
;
};
9A94D1081B8A3F5100F586A5
/* MaterialPulseView.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MaterialPulseView.swift
;
sourceTree
=
"<group>"
;
};
9A94D10A1B8A485C00F586A5
/* ImageCard.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ImageCard.swift
;
sourceTree
=
"<group>"
;
};
9A94D10A1B8A485C00F586A5
/* ImageCard.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ImageCard.swift
;
sourceTree
=
"<group>"
;
};
9AAC384C1B89528900FE6B2D
/* BasicCard.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BasicCard.swift
;
sourceTree
=
"<group>"
;
};
9AAC384C1B89528900FE6B2D
/* BasicCard.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
BasicCard.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -193,6 +195,7 @@
...
@@ -193,6 +195,7 @@
children
=
(
children
=
(
65B9657D1B8A7C330055B139
/* MaterialButton.swift */
,
65B9657D1B8A7C330055B139
/* MaterialButton.swift */
,
963832601B88E5BF0015F710
/* FabButton.swift */
,
963832601B88E5BF0015F710
/* FabButton.swift */
,
9638329D1B8EC34D0015F710
/* AddFabButton.swift */
,
963832611B88E5BF0015F710
/* FlatButton.swift */
,
963832611B88E5BF0015F710
/* FlatButton.swift */
,
963832651B88E5BF0015F710
/* RaisedButton.swift */
,
963832651B88E5BF0015F710
/* RaisedButton.swift */
,
);
);
...
@@ -367,6 +370,7 @@
...
@@ -367,6 +370,7 @@
65B965751B8A60A00055B139
/* MaterialView.swift in Sources */
,
65B965751B8A60A00055B139
/* MaterialView.swift in Sources */
,
963832711B88E5BF0015F710
/* Text.swift in Sources */
,
963832711B88E5BF0015F710
/* Text.swift in Sources */
,
9638326A1B88E5BF0015F710
/* CapturePreview.swift in Sources */
,
9638326A1B88E5BF0015F710
/* CapturePreview.swift in Sources */
,
9638329E1B8EC34D0015F710
/* AddFabButton.swift in Sources */
,
65B965721B8A578D0055B139
/* MaterialViewController.swift in Sources */
,
65B965721B8A578D0055B139
/* MaterialViewController.swift in Sources */
,
9AAC38541B89559900FE6B2D
/* Roboto.swift in Sources */
,
9AAC38541B89559900FE6B2D
/* Roboto.swift in Sources */
,
65B9657E1B8A7C330055B139
/* MaterialButton.swift in Sources */
,
65B9657E1B8A7C330055B139
/* MaterialButton.swift in Sources */
,
...
...
Source/AddFabButton.swift
0 → 100644
View file @
62eb6c6d
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import
UIKit
public
class
AddFabButton
:
FabButton
{
private
var
verticalLine
:
UIView
!
private
var
horizontalLine
:
UIView
!
//
// :name: prepareButton
//
public
override
func
prepareButton
()
{
super
.
prepareButton
()
prepareVerticalLine
()
prepareHorizontalLine
()
}
//
// :name: prepareVerticalLine
//
private
func
prepareVerticalLine
()
{
verticalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
lineWidth
,
CGRectGetHeight
(
backgroundColorView
.
frame
)
/
3
))
verticalLine
.
backgroundColor
=
.
whiteColor
()
verticalLine
.
center
=
backgroundColorView
.
center
backgroundColorView
.
addSubview
(
verticalLine
)
}
//
// :name: prepareHorizontalLine
//
private
func
prepareHorizontalLine
()
{
horizontalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
CGRectGetWidth
(
backgroundColorView
.
frame
)
/
3
,
lineWidth
))
horizontalLine
.
backgroundColor
=
.
whiteColor
()
horizontalLine
.
center
=
backgroundColorView
.
center
backgroundColorView
.
addSubview
(
horizontalLine
)
}
}
Source/FabButton.swift
View file @
62eb6c6d
...
@@ -19,141 +19,29 @@
...
@@ -19,141 +19,29 @@
import
UIKit
import
UIKit
public
class
FabButton
:
MaterialButton
{
public
class
FabButton
:
MaterialButton
{
/**
var
lineWidth
:
CGFloat
=
2.0
:name: lineWidth
*/
public
var
lineWidth
:
CGFloat
=
2
public
convenience
init
()
{
//
self
.
init
(
frame
:
CGRectZero
)
// :name: prepareButton
}
//
internal
override
func
prepareButton
()
{
public
override
func
drawRect
(
rect
:
CGRect
)
{
super
.
prepareButton
()
setupContext
(
rect
)
color
=
.
redColor
()
setupBackgroundColorView
()
pulseColor
=
.
whiteColor
()
setupPlus
()
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
}
public
required
init
(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
initialize
()
applyShadow
()
}
public
required
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
initialize
()
applyShadow
()
}
func
initialize
()
{
color
=
UIColor
.
redColor
()
pulseColor
=
UIColor
.
whiteColor
()
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
}
func
setupContext
(
rect
:
CGRect
)
{
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextAddEllipseInRect
(
context
,
rect
)
CGContextSetFillColorWithColor
(
context
,
UIColor
.
clearColor
()
.
CGColor
)
CGContextFillPath
(
context
)
CGContextRestoreGState
(
context
);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func
setupBackgroundColorView
()
{
backgroundColorView
=
UIView
()
backgroundColorView
!.
frame
=
bounds
backgroundColorView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2.0
backgroundColorView
!.
backgroundColor
=
color
backgroundColorView
!.
layer
.
masksToBounds
=
true
backgroundColorView
!.
userInteractionEnabled
=
false
insertSubview
(
backgroundColorView
!
,
atIndex
:
0
)
}
// I make the + with two views because
// The label is not actually vertically and horizontally aligned
// Quick hack instead of subclassing UILabel and override drawTextInRect
func
setupPlus
()
{
setupVerticalLine
()
setupHorizontalLine
()
}
func
setupVerticalLine
()
{
verticalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
lineWidth
,
CGRectGetHeight
(
backgroundColorView
!.
frame
)
/
3.0
))
verticalLine
!.
backgroundColor
=
UIColor
.
whiteColor
()
verticalLine
!.
center
=
backgroundColorView
!.
center
backgroundColorView
!.
addSubview
(
verticalLine
!
)
}
}
func
setupHorizontalLine
()
{
horizontalLine
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
CGRectGetWidth
(
backgroundColorView
!.
frame
)
/
3.0
,
lineWidth
))
horizontalLine
!.
backgroundColor
=
UIColor
.
whiteColor
()
horizontalLine
!.
center
=
backgroundColorView
!.
center
backgroundColorView
!.
addSubview
(
horizontalLine
!
)
}
func
applyShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
pulseTouches
(
touches
)
}
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>!
,
withEvent
event
:
UIEvent
!
)
{
//
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
// :name: pulseTouches
shrink
()
//
removePulse
()
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
super
.
pulseTouches
(
touches
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
3
,
3
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.1
,
1.1
)
})
}
}
func
pulseTouches
(
touches
:
NSSet
)
{
let
touch
=
touches
.
allObjects
.
last
as!
UITouch
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
bounds
.
width
,
bounds
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2.0
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
!.
addSubview
(
pulseView
!
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
3
,
3
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.1
,
1.1
)
},
completion
:
nil
)
}
func
shrink
()
{
UIView
.
animateWithDuration
(
0.3
,
delay
:
0.0
,
usingSpringWithDamping
:
0.2
,
initialSpringVelocity
:
10
,
options
:
nil
,
animations
:
{
self
.
transform
=
CGAffineTransformIdentity
},
completion
:
nil
)
}
func
removePulse
()
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
_
in
self
.
pulseView
?
.
alpha
=
0.0
})
{
(
finished
)
->
Void
in
self
.
pulseView
?
.
removeFromSuperview
()
self
.
pulseView
=
nil
}
}
}
}
Source/FlatButton.swift
View file @
62eb6c6d
...
@@ -19,104 +19,30 @@
...
@@ -19,104 +19,30 @@
import
UIKit
import
UIKit
public
class
FlatButton
:
MaterialButton
{
public
class
FlatButton
:
MaterialButton
{
public
var
textColor
:
UIColor
?
/**
:name: textColor
*/
public
var
textColor
:
UIColor
?
public
override
func
drawRect
(
rect
:
CGRect
)
{
//
setupContext
(
rect
)
// :name: prepareButton
setupBackgroundColorView
()
//
}
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
public
required
init
(
coder
aDecoder
:
NSCoder
)
{
pulseColor
=
.
whiteColor
()
super
.
init
(
coder
:
aDecoder
)
backgroundColorView
.
layer
.
cornerRadius
=
3
initialize
()
}
applyShadow
()
}
//
// :name: pulseTouches
public
required
override
init
(
frame
:
CGRect
)
{
//
super
.
init
(
frame
:
frame
)
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
initialize
()
super
.
pulseTouches
(
touches
)
applyShadow
()
textColor
=
titleLabel
?
.
textColor
}
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
func
initialize
()
{
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
backgroundColorView
=
UIView
()
self
.
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
pulseColor
=
UIColor
.
whiteColor
()
})
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
}
}
func
setupContext
(
rect
:
CGRect
)
{
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextSetFillColorWithColor
(
context
,
UIColor
.
clearColor
()
.
CGColor
)
CGContextFillPath
(
context
)
CGContextRestoreGState
(
context
);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
func
setupBackgroundColorView
()
{
backgroundColorView
!.
frame
=
self
.
bounds
backgroundColorView
!.
layer
.
cornerRadius
=
3.0
backgroundColorView
!.
backgroundColor
=
UIColor
.
clearColor
()
backgroundColorView
!.
layer
.
masksToBounds
=
true
backgroundColorView
!.
userInteractionEnabled
=
false
self
.
insertSubview
(
backgroundColorView
!
,
atIndex
:
0
)
}
func
applyShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
pulseTouches
(
touches
)
}
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>!
,
withEvent
event
:
UIEvent
!
)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
func
pulseTouches
(
touches
:
NSSet
)
{
let
touch
=
touches
.
allObjects
.
last
as!
UITouch
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2.0
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
!.
addSubview
(
pulseView
!
)
textColor
=
self
.
titleLabel
?
.
textColor
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
self
.
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
},
completion
:
nil
)
}
func
shrink
()
{
UIView
.
animateWithDuration
(
0.3
,
delay
:
0.0
,
usingSpringWithDamping
:
0.2
,
initialSpringVelocity
:
10
,
options
:
nil
,
animations
:
{
self
.
transform
=
CGAffineTransformIdentity
},
completion
:
nil
)
}
func
removePulse
()
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
()
->
Void
in
self
.
pulseView
!.
alpha
=
0.0
self
.
setTitleColor
(
self
.
textColor
,
forState
:
.
Normal
)
})
{
(
finished
)
->
Void
in
self
.
pulseView
!.
removeFromSuperview
()
self
.
pulseView
=
nil
}
}
}
}
Source/MaterialButton.swift
View file @
62eb6c6d
...
@@ -19,11 +19,174 @@
...
@@ -19,11 +19,174 @@
import
UIKit
import
UIKit
public
class
MaterialButton
:
UIButton
{
public
class
MaterialButton
:
UIButton
{
//
// :name: backgroundColorView
//
internal
lazy
var
backgroundColorView
:
UIView
=
UIView
()
//
// :name: pulseView
//
internal
var
pulseView
:
UIView
?
/**
:name: color
*/
public
var
color
:
UIColor
?
public
var
color
:
UIColor
?
/**
:name: pulseColor
*/
public
var
pulseColor
:
UIColor
?
public
var
pulseColor
:
UIColor
?
internal
var
pulseView
:
UIView
?
/**
internal
var
verticalLine
:
UIView
?
:name: init
internal
var
horizontalLine
:
UIView
?
*/
internal
var
backgroundColorView
:
UIView
?
public
required
init
(
coder
aDecoder
:
NSCoder
)
{
super
.
init
(
coder
:
aDecoder
)
prepareView
()
}
/**
:name: init
*/
public
required
override
init
(
frame
:
CGRect
)
{
super
.
init
(
frame
:
frame
)
prepareView
()
}
/**
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRectZero
)
}
/**
:name: touchesBegan
*/
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
pulseTouches
(
touches
)
}
/**
:name: touchesEnded
*/
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
/**
:name: touchesCancelled
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>!
,
withEvent
event
:
UIEvent
!
)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
/**
:name: drawRect
*/
final
public
override
func
drawRect
(
rect
:
CGRect
)
{
prepareContext
(
rect
)
prepareShadow
()
prepareButton
()
prepareBackgroundColorView
()
}
//
// :name: prepareButton
//
internal
func
prepareButton
()
{
backgroundColorView
.
frame
=
bounds
}
//
// :name: pulseTouches
//
internal
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
let
touch
=
touches
.
first
as!
UITouch
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
bounds
.
width
,
bounds
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
width
/
2
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
.
addSubview
(
pulseView
!
)
}
//
// :name: prepareBackgroundColorView
//
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private
func
prepareBackgroundColorView
()
{
backgroundColorView
.
backgroundColor
=
color
backgroundColorView
.
layer
.
masksToBounds
=
true
backgroundColorView
.
userInteractionEnabled
=
false
insertSubview
(
backgroundColorView
,
atIndex
:
0
)
}
//
// :name: prepareView
//
private
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
}
//
// :name: prepareShadow
//
private
func
prepareShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
//
// :name: prepareContext
//
private
func
prepareContext
(
rect
:
CGRect
)
{
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextAddEllipseInRect
(
context
,
rect
)
CGContextSetFillColorWithColor
(
context
,
UIColor
.
clearColor
()
.
CGColor
)
CGContextFillPath
(
context
)
CGContextRestoreGState
(
context
);
}
//
// :name: shrink
//
private
func
shrink
()
{
UIView
.
animateWithDuration
(
0.3
,
delay
:
0
,
usingSpringWithDamping
:
0.2
,
initialSpringVelocity
:
10
,
options
:
nil
,
animations
:
{
self
.
transform
=
CGAffineTransformIdentity
},
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 @
62eb6c6d
...
@@ -19,112 +19,32 @@
...
@@ -19,112 +19,32 @@
import
UIKit
import
UIKit
public
class
RaisedButton
:
MaterialButton
{
public
class
RaisedButton
:
MaterialButton
{
public
override
func
drawRect
(
rect
:
CGRect
)
{
/**
setupContext
(
rect
)
:name: textColor
setupBackgroundColorView
()
*/
}
public
var
textColor
:
UIColor
?
public
required
init
(
coder
aDecoder
:
NSCoder
)
{
//
super
.
init
(
coder
:
aDecoder
)
// :name: prepareButton
initialize
()
//
applyShadow
()
internal
override
func
prepareButton
()
{
}
super
.
prepareButton
()
color
=
.
redColor
()
public
required
override
init
(
frame
:
CGRect
)
{
pulseColor
=
.
whiteColor
()
super
.
init
(
frame
:
frame
)
backgroundColorView
.
layer
.
cornerRadius
=
3
initialize
()
}
applyShadow
()
}
//
// :name: pulseTouches
func
initialize
()
{
//
color
=
UIColor
.
redColor
()
internal
override
func
pulseTouches
(
touches
:
Set
<
NSObject
>
)
{
backgroundColorView
=
UIView
()
super
.
pulseTouches
(
touches
)
pulseColor
=
UIColor
.
whiteColor
()
textColor
=
titleLabel
?
.
textColor
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
}
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
public
override
func
touchesBegan
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
self
.
setTitleColor
(
UIColor
.
whiteColor
(),
forState
:
.
Normal
)
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
})
pulseTouches
(
touches
)
}
public
override
func
touchesEnded
(
touches
:
Set
<
NSObject
>
,
withEvent
event
:
UIEvent
)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
public
override
func
touchesCancelled
(
touches
:
Set
<
NSObject
>!
,
withEvent
event
:
UIEvent
!
)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
shrink
()
removePulse
()
}
private
func
setupContext
(
rect
:
CGRect
)
{
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextSetFillColorWithColor
(
context
,
UIColor
.
clearColor
()
.
CGColor
)
CGContextFillPath
(
context
)
CGContextRestoreGState
(
context
);
}
// We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button
private
func
setupBackgroundColorView
()
{
backgroundColorView
!.
frame
=
self
.
bounds
backgroundColorView
!.
layer
.
cornerRadius
=
3.0
backgroundColorView
!.
backgroundColor
=
color
!
backgroundColorView
!.
layer
.
masksToBounds
=
true
backgroundColorView
!.
userInteractionEnabled
=
false
self
.
insertSubview
(
backgroundColorView
!
,
atIndex
:
0
)
}
private
func
applyShadow
()
{
layer
.
shadowOffset
=
CGSizeMake
(
1
,
1
)
layer
.
shadowColor
=
UIColor
.
blackColor
()
.
CGColor
layer
.
shadowOpacity
=
0.5
layer
.
shadowRadius
=
5
}
private
func
pulseTouches
(
touches
:
NSSet
)
{
let
touch
=
touches
.
allObjects
.
last
as!
UITouch
let
touchLocation
=
touch
.
locationInView
(
self
)
pulseView
=
UIView
()
pulseView
!.
frame
=
CGRectMake
(
0
,
0
,
self
.
bounds
.
size
.
height
,
self
.
bounds
.
size
.
height
)
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2.0
pulseView
!.
center
=
touchLocation
pulseView
!.
backgroundColor
=
pulseColor
!.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
!.
addSubview
(
pulseView
!
)
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
10
,
10
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.1
)
},
completion
:
nil
)
}
private
func
shrink
()
{
UIView
.
animateWithDuration
(
0.3
,
delay
:
0.0
,
usingSpringWithDamping
:
0.2
,
initialSpringVelocity
:
10
,
options
:
nil
,
animations
:
{
self
.
transform
=
CGAffineTransformIdentity
},
completion
:
nil
)
}
private
func
removePulse
()
{
UIView
.
animateWithDuration
(
0.3
,
animations
:
{
()
->
Void
in
self
.
pulseView
!.
alpha
=
0.0
})
{
_
in
self
.
pulseView
!.
removeFromSuperview
()
self
.
pulseView
=
nil
}
}
}
}
}
Source/SideNavController.swift
View file @
62eb6c6d
This diff is collapsed.
Click to expand it.
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