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
2e6af65c
Commit
2e6af65c
authored
Aug 29, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-7: fully editable MaterialButtons
parent
a2d32af3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
80 deletions
+98
-80
Source/BasicCard.swift
+32
-40
Source/FabButton.swift
+10
-2
Source/FlatButton.swift
+12
-5
Source/MaterialButton.swift
+16
-15
Source/MaterialCard.swift
+15
-12
Source/MaterialTheme.swift
+1
-1
Source/RaisedButton.swift
+12
-5
No files found.
Source/BasicCard.swift
View file @
2e6af65c
...
...
@@ -24,15 +24,16 @@ public class BasicCard : MaterialCard {
// :name: layoutConstraints
//
internal
lazy
var
layoutConstraints
:
Array
<
NSLayoutConstraint
>
=
Array
<
NSLayoutConstraint
>
()
//
// :name: views
//
internal
lazy
var
views
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
/
**
:name: buttons
*
/
public
var
buttons
:
Array
<
MaterialButton
>
?
/
/
// :name: horizontalSeparator
/
/
public
lazy
var
horizontalSeparator
:
UIView
=
UIView
()
/**
:name: titleLabel
...
...
@@ -60,8 +61,18 @@ public class BasicCard : MaterialCard {
}
}
public
var
horizontalSeparator
:
UIView
?
/**
:name: buttons
*/
public
var
buttons
:
Array
<
MaterialButton
>
?
{
didSet
{
prepareCard
()
}
}
//
// :name: prepareCard
//
internal
override
func
prepareCard
()
{
super
.
prepareCard
()
prepareShadow
()
...
...
@@ -87,6 +98,21 @@ public class BasicCard : MaterialCard {
views
[
"detailTextLabel"
]
=
detailTextLabel
!
}
if
nil
!=
buttons
{
var
horizontalFormat
:
String
=
"H:|"
var
buttonViews
:
Dictionary
<
String
,
AnyObject
>
=
Dictionary
<
String
,
AnyObject
>
()
for
var
i
:
Int
=
0
,
l
:
Int
=
buttons
!.
count
;
i
<
l
;
++
i
{
let
button
:
MaterialButton
=
buttons
!
[
i
]
addSubview
(
button
)
buttonViews
[
"button
\(
i
)
"
]
=
button
views
[
"button
\(
i
)
"
]
=
button
as
AnyObject
horizontalFormat
+=
"-(20)-[button
\(
i
)
]"
verticalFormat
+=
"-(20)-[button
\(
i
)
]"
}
horizontalFormat
+=
"-(20)-|"
layoutConstraints
+=
Layout
.
constraint
(
horizontalFormat
,
options
:
nil
,
metrics
:
nil
,
views
:
buttonViews
)
}
// addConstraints(Layout.constraint("H:|-(20)-[detailTextLabel]-(20)-|", options: nil, metrics: nil, views: ["detailTextLabel": detailTextLabel]))
// addConstraints(Layout.constraint("H:|[horizontalSeparator]|", options: nil, metrics: nil, views: ["horizontalSeparator": horizontalSeparator]))
// addConstraints(Layout.constraint("H:|-(10)-[cancelButton(80)]-(10)-[otherButton(80)]", options: nil, metrics: nil, views: ["cancelButton": cancelButton, "otherButton": otherButton]))
...
...
@@ -100,38 +126,4 @@ public class BasicCard : MaterialCard {
NSLayoutConstraint
.
activateConstraints
(
layoutConstraints
)
}
}
//
// private func prepareDetailTextLabel() {
// detailTextLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
// detailTextLabel.font = Roboto.lightWithSize(16.0)
// detailTextLabel.textColor = UIColor.whiteColor()
// detailTextLabel.text = "I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively."
// detailTextLabel.numberOfLines = 0
// detailTextLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
// addSubview(detailTextLabel)
// }
//
// private func prepareHorizontalSeparator() {
// horizontalSeparator.setTranslatesAutoresizingMaskIntoConstraints(false)
// horizontalSeparator.backgroundColor = UIColor.whiteColor()
// horizontalSeparator.alpha = 0.2
// addSubview(horizontalSeparator)
// }
//
// private func prepareCancelButton() {
// cancelButton.setTranslatesAutoresizingMaskIntoConstraints(false)
// cancelButton.setTitle("Cancel", forState: .Normal)
// cancelButton.setTitleColor(buttonColor, forState: .Normal)
// cancelButton.pulseColor = buttonColor
// addSubview(cancelButton)
// }
//
// private func prepareOtherButton() {
// otherButton.setTranslatesAutoresizingMaskIntoConstraints(false)
// otherButton.setTitle("Confirm", forState: .Normal)
// otherButton.setTitleColor(buttonColor, forState: .Normal)
// otherButton.pulseColor = buttonColor
// addSubview(otherButton)
// }
}
Source/FabButton.swift
View file @
2e6af65c
...
...
@@ -22,11 +22,19 @@ public class FabButton : MaterialButton {
//
// :name: prepareButton
//
internal
override
func
prepareView
()
{
super
.
prepareView
()
setTitleColor
(
MaterialTheme
.
white
.
color
,
forState
:
.
Normal
)
backgroundColor
=
MaterialTheme
.
red
.
darken1
}
//
// :name: prepareButton
//
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
prepareShadow
()
backgroundColor
=
MaterialTheme
.
red
.
darken1
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
backgroundColorView
.
layer
.
cornerRadius
=
bounds
.
width
/
2
}
//
...
...
Source/FlatButton.swift
View file @
2e6af65c
...
...
@@ -20,13 +20,20 @@ import UIKit
public
class
FlatButton
:
MaterialButton
{
//
// :name: prepare
Button
// :name: prepare
View
//
internal
override
func
prepare
Button
()
{
super
.
prepare
Button
()
internal
override
func
prepare
View
()
{
super
.
prepare
View
()
setTitleColor
(
MaterialTheme
.
indigo
.
darken1
,
forState
:
.
Normal
)
pulseColor
=
MaterialTheme
.
indigo
.
darken1
backgroundColor
=
MaterialTheme
.
clear
.
color
}
//
// :name: prepareButton
//
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
backgroundColorView
.
layer
.
cornerRadius
=
3
}
...
...
@@ -36,8 +43,8 @@ public class FlatButton : MaterialButton {
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
)
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
4
,
4
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.
05
)
})
}
}
Source/MaterialButton.swift
View file @
2e6af65c
...
...
@@ -33,15 +33,18 @@ public class MaterialButton : UIButton {
:name: backgroundColor
*/
public
override
var
backgroundColor
:
UIColor
?
{
didSet
{
backgroundColorView
.
backgroundColor
=
backgroundColor
get
{
return
backgroundColorView
.
backgroundColor
}
set
(
value
)
{
backgroundColorView
.
backgroundColor
=
value
}
}
/**
:name: pulseColor
*/
public
var
pulseColor
:
UIColor
=
MaterialTheme
.
white
.
color
public
var
pulseColor
:
UIColor
?
=
MaterialTheme
.
white
.
color
/**
:name: init
...
...
@@ -66,14 +69,6 @@ public class MaterialButton : UIButton {
self
.
init
(
frame
:
CGRectZero
)
}
//
// :name: prepareView
//
private
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
prepareBackgroundColorView
()
}
/**
:name: touchesBegan
*/
...
...
@@ -109,13 +104,19 @@ public class MaterialButton : UIButton {
}
//
// :name: prepare
Button
// :name: prepare
View
//
internal
func
prepareButton
()
{
internal
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
prepareBackgroundColorView
()
}
//
// :name: prepareButton
//
internal
func
prepareButton
()
{}
//
// :name: prepareShadow
//
internal
func
prepareShadow
()
{
...
...
@@ -132,7 +133,7 @@ public class MaterialButton : UIButton {
pulseView
=
UIView
(
frame
:
CGRectMake
(
0
,
0
,
bounds
.
height
,
bounds
.
height
))
pulseView
!.
layer
.
cornerRadius
=
bounds
.
height
/
2
pulseView
!.
center
=
(
touches
.
first
as!
UITouch
)
.
locationInView
(
self
)
pulseView
!.
backgroundColor
=
pulseColor
.
colorWithAlphaComponent
(
0.5
)
pulseView
!.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
backgroundColorView
.
addSubview
(
pulseView
!
)
}
...
...
@@ -157,7 +158,7 @@ public class MaterialButton : UIButton {
let
context
=
UIGraphicsGetCurrentContext
()
CGContextSaveGState
(
context
);
CGContextAddEllipseInRect
(
context
,
rect
)
CGContextSetFillColorWithColor
(
context
,
UIColor
.
clearColor
()
.
CGColor
)
CGContextSetFillColorWithColor
(
context
,
MaterialTheme
.
clear
.
color
.
CGColor
)
CGContextFillPath
(
context
)
CGContextRestoreGState
(
context
);
}
...
...
Source/MaterialCard.swift
View file @
2e6af65c
...
...
@@ -33,8 +33,11 @@ public class MaterialCard : UIView {
:name: backgroundColor
*/
public
override
var
backgroundColor
:
UIColor
?
{
didSet
{
backgroundColorView
.
backgroundColor
=
backgroundColor
get
{
return
backgroundColorView
.
backgroundColor
}
set
(
value
)
{
backgroundColorView
.
backgroundColor
=
value
}
}
...
...
@@ -66,14 +69,6 @@ public class MaterialCard : UIView {
self
.
init
(
frame
:
CGRectZero
)
}
//
// :name: prepareView
//
private
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
prepareCard
()
}
/**
:name: touchesBegan
*/
...
...
@@ -101,13 +96,20 @@ public class MaterialCard : UIView {
}
//
// :name: prepare
Card
// :name: prepare
View
//
internal
func
prepareCard
()
{
internal
func
prepareView
()
{
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
prepareBackgroundColorView
()
prepareCard
()
}
//
// :name: prepareCard
//
internal
func
prepareCard
()
{}
//
// :name: prepareShadow
//
internal
func
prepareShadow
()
{
...
...
@@ -166,6 +168,7 @@ public class MaterialCard : UIView {
backgroundColorView
.
setTranslatesAutoresizingMaskIntoConstraints
(
false
)
backgroundColorView
.
layer
.
cornerRadius
=
2
backgroundColorView
.
layer
.
masksToBounds
=
true
backgroundColorView
.
clipsToBounds
=
true
backgroundColorView
.
userInteractionEnabled
=
false
insertSubview
(
backgroundColorView
,
atIndex
:
0
)
Layout
.
expandToParentSize
(
self
,
child
:
backgroundColorView
)
...
...
Source/MaterialTheme.swift
View file @
2e6af65c
...
...
@@ -21,7 +21,7 @@ import UIKit
public
struct
MaterialTheme
{
// clear
public
struct
clear
{
public
static
let
color
:
UIColor
=
UIColor
.
clearColor
(
)
public
static
let
color
:
UIColor
=
white
.
color
.
colorWithAlphaComponent
(
0
)
}
// white
...
...
Source/RaisedButton.swift
View file @
2e6af65c
...
...
@@ -22,11 +22,18 @@ public class RaisedButton : MaterialButton {
//
// :name: prepareButton
//
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
prepareShadow
()
internal
override
func
prepareView
()
{
super
.
prepareView
()
setTitleColor
(
MaterialTheme
.
white
.
color
,
forState
:
.
Normal
)
backgroundColor
=
MaterialTheme
.
indigo
.
darken1
}
//
// :name: prepareButton
//
internal
override
func
prepareButton
()
{
super
.
prepareButton
()
prepareShadow
()
backgroundColorView
.
layer
.
cornerRadius
=
3
}
...
...
@@ -36,8 +43,8 @@ public class RaisedButton : MaterialButton {
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
)
self
.
pulseView
!.
transform
=
CGAffineTransformMakeScale
(
4
,
4
)
self
.
transform
=
CGAffineTransformMakeScale
(
1.05
,
1.
05
)
})
}
}
...
...
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