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
3744a4a9
Commit
3744a4a9
authored
Feb 15, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated MaterialSwitch example
parent
a1629384
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
126 deletions
+81
-126
Examples/Programmatic/MaterialSwitch/MaterialSwitch.xcodeproj/project.pbxproj
+0
-6
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/Contents.json
+0
-24
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt_2x.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt_3x.png
+0
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Info.plist
+0
-2
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
+58
-71
Sources/MaterialSwitch.swift
+23
-23
No files found.
Examples/Programmatic/MaterialSwitch/MaterialSwitch.xcodeproj/project.pbxproj
View file @
3744a4a9
...
...
@@ -11,8 +11,6 @@
96A71ED71C6FFF7300C0C4AE
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A71ED61C6FFF7300C0C4AE
/* ViewController.swift */
;
};
96A71EDC1C6FFF7300C0C4AE
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A71EDB1C6FFF7300C0C4AE
/* Assets.xcassets */
;
};
96A71EDF1C6FFF7300C0C4AE
/* LaunchScreen.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A71EDD1C6FFF7300C0C4AE
/* LaunchScreen.storyboard */
;
};
96A71EE71C70007600C0C4AE
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A71EE61C70007600C0C4AE
/* Material.framework */
;
};
96A71EE81C70007600C0C4AE
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A71EE61C70007600C0C4AE
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -22,7 +20,6 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
96A71EE81C70007600C0C4AE
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -36,7 +33,6 @@
96A71EDB1C6FFF7300C0C4AE
/* Assets.xcassets */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder.assetcatalog
;
path
=
Assets.xcassets
;
sourceTree
=
"<group>"
;
};
96A71EDE1C6FFF7300C0C4AE
/* Base */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file.storyboard
;
name
=
Base
;
path
=
Base.lproj/LaunchScreen.storyboard
;
sourceTree
=
"<group>"
;
};
96A71EE01C6FFF7300C0C4AE
/* Info.plist */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.plist.xml
;
path
=
Info.plist
;
sourceTree
=
"<group>"
;
};
96A71EE61C70007600C0C4AE
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -44,7 +40,6 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
96A71EE71C70007600C0C4AE
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -54,7 +49,6 @@
96A71EC81C6FFF7300C0C4AE
=
{
isa
=
PBXGroup
;
children
=
(
96A71EE61C70007600C0C4AE
/* Material.framework */
,
96A71ED31C6FFF7300C0C4AE
/* MaterialSwitch */
,
96A71ED21C6FFF7300C0C4AE
/* Products */
,
);
...
...
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/Contents.json
deleted
100644 → 0
View file @
a1629384
{
"images"
:
[
{
"idiom"
:
"universal"
,
"filename"
:
"ic_alarm_white_18pt.png"
,
"scale"
:
"1x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_alarm_white_18pt_2x.png"
,
"scale"
:
"2x"
},
{
"idiom"
:
"universal"
,
"filename"
:
"ic_alarm_white_18pt_3x.png"
,
"scale"
:
"3x"
}
],
"info"
:
{
"version"
:
1
,
"author"
:
"xcode"
}
}
\ No newline at end of file
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt.png
deleted
100644 → 0
View file @
a1629384
336 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt_2x.png
deleted
100644 → 0
View file @
a1629384
610 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Assets.xcassets/ic_alarm_white_18pt.imageset/ic_alarm_white_18pt_3x.png
deleted
100644 → 0
View file @
a1629384
977 Bytes
Examples/Programmatic/MaterialSwitch/MaterialSwitch/Info.plist
View file @
3744a4a9
...
...
@@ -42,7 +42,5 @@
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
UIViewControllerBasedStatusBarAppearance
<
/k
e
y
>
<
fa
ls
e
/
>
<
/
d
i
c
t
>
<
/plist
>
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
View file @
3744a4a9
...
...
@@ -36,94 +36,81 @@ import UIKit
import
Material
class
ViewController
:
UIViewController
,
MaterialSwitchDelegate
{
private
var
topView
:
MaterialView
=
MaterialView
()
private
var
bottomView
:
MaterialView
=
MaterialView
()
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
prepare
Small
MaterialSwitch
()
prepare
LightContent
MaterialSwitch
()
prepareDefaultMaterialSwitch
()
prepareLargeMaterialSwitch
()
prepareLightOnDisabledMaterialSwitch
()
prepareLightOffDisabledMaterialSwitch
()
prepareDarkOnDisabledMaterialSwitch
()
prepareDarkOffDisabledMaterialSwitch
()
}
/// General preparation statements.
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
view
.
addSubview
(
topView
)
topView
.
translatesAutoresizingMaskIntoConstraints
=
false
view
.
addSubview
(
bottomView
)
bottomView
.
translatesAutoresizingMaskIntoConstraints
=
false
bottomView
.
backgroundColor
=
MaterialColor
.
grey
.
darken4
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
topView
)
MaterialLayout
.
alignToParentHorizontally
(
view
,
child
:
bottomView
)
MaterialLayout
.
alignToParentVertically
(
view
,
children
:
[
topView
,
bottomView
])
}
/// Prepares the Small MaterialSwitch.
private
func
prepareSmallMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Small
)
switchControl
.
center
=
view
.
center
switchControl
.
y
-=
100
switchControl
.
delegate
=
self
view
.
addSubview
(
switchControl
)
/// Prepares the LightContent MaterialSwitch.
private
func
prepareLightContentMaterialSwitch
()
{
let
c1
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Small
)
c1
.
delegate
=
self
c1
.
translatesAutoresizingMaskIntoConstraints
=
false
topView
.
addSubview
(
c1
)
let
c2
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
LightContent
)
c2
.
delegate
=
self
c2
.
translatesAutoresizingMaskIntoConstraints
=
false
topView
.
addSubview
(
c2
)
let
c3
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Large
)
c3
.
delegate
=
self
c3
.
enabled
=
false
c3
.
translatesAutoresizingMaskIntoConstraints
=
false
topView
.
addSubview
(
c3
)
MaterialLayout
.
alignToParentHorizontally
(
topView
,
child
:
c1
)
MaterialLayout
.
alignToParentHorizontally
(
topView
,
child
:
c2
)
MaterialLayout
.
alignToParentHorizontally
(
topView
,
child
:
c3
)
MaterialLayout
.
alignToParentVertically
(
topView
,
children
:
[
c1
,
c2
,
c3
])
}
/// Prepares the
Defaul
t MaterialSwitch.
/// Prepares the
LightConten
t MaterialSwitch.
private
func
prepareDefaultMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
)
switchControl
.
delegate
=
self
let
c1
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Default
,
size
:
.
Small
)
c1
.
delegate
=
self
c1
.
translatesAutoresizingMaskIntoConstraints
=
false
bottomView
.
addSubview
(
c1
)
view
.
addSubview
(
switchControl
)
switchControl
.
translatesAutoresizingMaskIntoConstraints
=
false
MaterialLayout
.
alignFromBottomRight
(
view
,
child
:
switchControl
,
bottom
:
16
,
right
:
16
)
}
/// Prepares the Large MaterialSwitch.
private
func
prepareLargeMaterialSwitch
()
{
let
image
:
UIImage
?
=
UIImage
(
named
:
"ic_alarm_white_18pt"
)
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
,
size
:
.
Large
)
switchControl
.
center
=
view
.
center
switchControl
.
y
-=
50
switchControl
.
delegate
=
self
switchControl
.
button
.
setImage
(
image
,
forState
:
.
Normal
)
switchControl
.
button
.
setImage
(
image
,
forState
:
.
Highlighted
)
view
.
addSubview
(
switchControl
)
}
/// Prepares the Light On enabled = false MaterialSwitch.
private
func
prepareLightOnDisabledMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Light
)
switchControl
.
enabled
=
false
switchControl
.
center
=
view
.
center
switchControl
.
delegate
=
self
view
.
addSubview
(
switchControl
)
}
/// Prepares the Light Off enabled = false MaterialSwitch.
private
func
prepareLightOffDisabledMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Light
)
switchControl
.
enabled
=
false
switchControl
.
center
=
view
.
center
switchControl
.
y
+=
50
switchControl
.
delegate
=
self
view
.
addSubview
(
switchControl
)
}
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOnDisabledMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
Dark
)
switchControl
.
enabled
=
false
switchControl
.
center
=
view
.
center
switchControl
.
y
+=
100
switchControl
.
delegate
=
self
view
.
addSubview
(
switchControl
)
}
/// Prepares the Dark On enabled = false MaterialSwitch.
private
func
prepareDarkOffDisabledMaterialSwitch
()
{
let
switchControl
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Dark
)
switchControl
.
enabled
=
false
switchControl
.
center
=
view
.
center
switchControl
.
y
+=
150
switchControl
.
delegate
=
self
view
.
addSubview
(
switchControl
)
let
c2
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
)
c2
.
delegate
=
self
c2
.
translatesAutoresizingMaskIntoConstraints
=
false
bottomView
.
addSubview
(
c2
)
let
c3
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
Default
,
size
:
.
Large
)
c3
.
delegate
=
self
c3
.
enabled
=
false
c3
.
translatesAutoresizingMaskIntoConstraints
=
false
bottomView
.
addSubview
(
c3
)
MaterialLayout
.
alignToParentHorizontally
(
bottomView
,
child
:
c1
)
MaterialLayout
.
alignToParentHorizontally
(
bottomView
,
child
:
c2
)
MaterialLayout
.
alignToParentHorizontally
(
bottomView
,
child
:
c3
)
MaterialLayout
.
alignToParentVertically
(
bottomView
,
children
:
[
c1
,
c2
,
c3
])
}
internal
func
switchControl
StateChanged
(
control
:
MaterialSwitch
,
state
:
MaterialSwitchState
)
{
internal
func
materialSwitch
StateChanged
(
control
:
MaterialSwitch
,
state
:
MaterialSwitchState
)
{
print
(
"MaterialSwitch - Size:
\(
control
.
switchSize
)
State:
\(
state
)
"
)
}
}
Sources/MaterialSwitch.swift
View file @
3744a4a9
...
...
@@ -31,8 +31,8 @@
import
UIKit
public
enum
MaterialSwitchStyle
{
case
Light
case
D
ark
case
Light
Content
case
D
efault
}
public
enum
MaterialSwitchState
{
...
...
@@ -169,27 +169,27 @@ public class MaterialSwitch: UIControl {
public
private(set)
var
switchState
:
MaterialSwitchState
=
.
Off
/// MaterialSwitch style.
public
var
switchStyle
:
MaterialSwitchStyle
=
.
Light
{
public
var
switchStyle
:
MaterialSwitchStyle
=
.
Light
Content
{
didSet
{
switch
switchStyle
{
case
.
Light
:
buttonOnColor
=
MaterialColor
.
blue
.
lighten1
trackOnColor
=
MaterialColor
.
blue
.
darken2
buttonOffColor
=
MaterialColor
.
grey
.
lighten2
trackOffColor
=
MaterialColor
.
grey
.
darken1
buttonOnDisabledColor
=
MaterialColor
.
blue
.
base
trackOnDisabledColor
=
MaterialColor
.
blue
.
dark
en3
buttonOffDisabledColor
=
MaterialColor
.
grey
.
base
trackOffDisabledColor
=
MaterialColor
.
grey
.
dark
en3
case
.
D
ark
:
buttonOnColor
=
MaterialColor
.
blueGrey
.
base
trackOnColor
=
MaterialColor
.
blueGrey
.
darken3
buttonOffColor
=
MaterialColor
.
grey
.
base
trackOffColor
=
MaterialColor
.
grey
.
darken3
buttonOnDisabledColor
=
MaterialColor
.
blueGrey
.
darken1
trackOnDisabledColor
=
MaterialColor
.
blueGrey
.
darken4
buttonOffDisabledColor
=
MaterialColor
.
grey
.
darken
1
trackOffDisabledColor
=
MaterialColor
.
grey
.
darken4
case
.
Light
Content
:
buttonOnColor
=
MaterialColor
.
lightBlue
.
darken3
trackOnColor
=
MaterialColor
.
lightBlue
.
lighten3
buttonOffColor
=
MaterialColor
.
blueGrey
.
lighten4
trackOffColor
=
MaterialColor
.
blueGrey
.
lighten3
buttonOnDisabledColor
=
MaterialColor
.
grey
.
lighten2
trackOnDisabledColor
=
MaterialColor
.
grey
.
light
en3
buttonOffDisabledColor
=
MaterialColor
.
grey
.
lighten2
trackOffDisabledColor
=
MaterialColor
.
grey
.
light
en3
case
.
D
efault
:
buttonOnColor
=
MaterialColor
.
lightBlue
.
lighten1
trackOnColor
=
MaterialColor
.
lightBlue
.
lighten2
.
colorWithAlphaComponent
(
0.5
)
buttonOffColor
=
MaterialColor
.
blueGrey
.
lighten3
trackOffColor
=
MaterialColor
.
blueGrey
.
lighten4
.
colorWithAlphaComponent
(
0.5
)
buttonOnDisabledColor
=
MaterialColor
.
grey
.
darken3
trackOnDisabledColor
=
MaterialColor
.
grey
.
lighten1
.
colorWithAlphaComponent
(
0.2
)
buttonOffDisabledColor
=
MaterialColor
.
grey
.
darken
3
trackOffDisabledColor
=
MaterialColor
.
grey
.
lighten1
.
colorWithAlphaComponent
(
0.2
)
}
}
}
...
...
@@ -237,7 +237,7 @@ public class MaterialSwitch: UIControl {
prepareTrack
()
prepareButton
()
prepareSwitchSize
(
.
Default
)
prepareSwitchStyle
(
.
Light
)
prepareSwitchStyle
(
.
Light
Content
)
prepareSwitchState
(
.
Off
)
}
...
...
@@ -247,7 +247,7 @@ public class MaterialSwitch: UIControl {
- Parameter style: A MaterialSwitchStyle value.
- Parameter size: A MaterialSwitchSize value.
*/
public
init
(
state
:
MaterialSwitchState
=
.
On
,
style
:
MaterialSwitchStyle
=
.
Ligh
t
,
size
:
MaterialSwitchSize
=
.
Default
)
{
public
init
(
state
:
MaterialSwitchState
=
.
On
,
style
:
MaterialSwitchStyle
=
.
Defaul
t
,
size
:
MaterialSwitchSize
=
.
Default
)
{
track
=
MaterialView
(
frame
:
CGRectZero
)
button
=
FabButton
(
frame
:
CGRectZero
)
super
.
init
(
frame
:
CGRectZero
)
...
...
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