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
3e1dc4a4
Commit
3e1dc4a4
authored
Feb 19, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated switchState setter to use property rather than setSwitchState
parent
91cebc7a
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
55 additions
and
87 deletions
+55
-87
Examples/Programmatic/MaterialSwitch/MaterialSwitch.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
+5
-1
Examples/Programmatic/NavigationBarViewController/NavigationBarViewController/AppNavigationBarViewController.swift
+2
-2
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/AppNavigationViewController.swift
+2
-2
Material.xcodeproj/project.pbxproj
+4
-20
Sources/ControlView.swift
+2
-2
Sources/MaterialSwitch.swift
+28
-45
Sources/NavigationBarView.swift
+5
-9
Sources/NavigationBarViewController.swift
+1
-1
Sources/StatusBarView.swift
+0
-5
No files found.
Examples/Programmatic/MaterialSwitch/MaterialSwitch.xcodeproj/project.pbxproj
View file @
3e1dc4a4
...
...
@@ -11,6 +11,8 @@
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 */
;
};
96A720071C76D75100C0C4AE
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A720061C76D75100C0C4AE
/* Material.framework */
;
};
96A720081C76D75100C0C4AE
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96A720061C76D75100C0C4AE
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
...
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstSubfolderSpec
=
10
;
files
=
(
96A720081C76D75100C0C4AE
/* Material.framework in Embed Frameworks */
,
);
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
...
...
@@ -33,6 +36,7 @@
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>"
;
};
96A720061C76D75100C0C4AE
/* 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 */
...
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
files
=
(
96A720071C76D75100C0C4AE
/* Material.framework in Frameworks */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
@@ -49,6 +54,7 @@
96A71EC81C6FFF7300C0C4AE
=
{
isa
=
PBXGroup
;
children
=
(
96A720061C76D75100C0C4AE
/* Material.framework */
,
96A71ED31C6FFF7300C0C4AE
/* MaterialSwitch */
,
96A71ED21C6FFF7300C0C4AE
/* Products */
,
);
...
...
Examples/Programmatic/MaterialSwitch/MaterialSwitch/ViewController.swift
View file @
3e1dc4a4
...
...
@@ -38,6 +38,7 @@ import Material
class
ViewController
:
UIViewController
,
MaterialSwitchDelegate
{
private
var
topView
:
MaterialView
=
MaterialView
()
private
var
bottomView
:
MaterialView
=
MaterialView
()
var
c2
:
MaterialSwitch
!
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -69,9 +70,10 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
c1
.
translatesAutoresizingMaskIntoConstraints
=
false
topView
.
addSubview
(
c1
)
let
c2
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
On
,
style
:
.
LightContent
)
c2
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
)
c2
.
delegate
=
self
c2
.
translatesAutoresizingMaskIntoConstraints
=
false
c2
.
switchState
=
.
On
topView
.
addSubview
(
c2
)
let
c3
:
MaterialSwitch
=
MaterialSwitch
(
state
:
.
Off
,
style
:
.
LightContent
,
size
:
.
Large
)
...
...
@@ -112,5 +114,7 @@ class ViewController: UIViewController, MaterialSwitchDelegate {
internal
func
materialSwitchStateChanged
(
control
:
MaterialSwitch
,
state
:
MaterialSwitchState
)
{
print
(
"MaterialSwitch - Size:
\(
control
.
switchSize
)
State:
\(
state
)
"
)
c2
.
switchState
=
state
}
}
Examples/Programmatic/NavigationBarViewController/NavigationBarViewController/AppNavigationBarViewController.swift
View file @
3e1dc4a4
...
...
@@ -125,7 +125,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
// Menu button.
let
menuButton
:
FlatButton
=
FlatButton
()
menuButton
.
pulseColor
=
nil
menuButton
.
pulseColor
=
MaterialColor
.
white
menuButton
.
pulseScale
=
false
menuButton
.
setImage
(
image
,
forState
:
.
Normal
)
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
...
...
@@ -137,7 +137,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
// Search button.
image
=
UIImage
(
named
:
"ic_more_horiz_white"
)
let
moreButton
:
FlatButton
=
FlatButton
()
moreButton
.
pulseColor
=
nil
moreButton
.
pulseColor
=
MaterialColor
.
white
moreButton
.
pulseScale
=
false
moreButton
.
setImage
(
image
,
forState
:
.
Normal
)
moreButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
...
...
Examples/Programmatic/SideNavigationViewController/SideNavigationViewController/AppNavigationViewController.swift
View file @
3e1dc4a4
...
...
@@ -140,7 +140,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
// Menu button.
let
menuButton
:
FlatButton
=
FlatButton
()
menuButton
.
pulseColor
=
nil
menuButton
.
pulseColor
=
MaterialColor
.
white
menuButton
.
pulseScale
=
false
menuButton
.
setImage
(
image
,
forState
:
.
Normal
)
menuButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
...
...
@@ -152,7 +152,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
// Search button.
image
=
UIImage
(
named
:
"ic_more_horiz_white"
)
let
moreButton
:
FlatButton
=
FlatButton
()
moreButton
.
pulseColor
=
nil
moreButton
.
pulseColor
=
MaterialColor
.
white
moreButton
.
pulseScale
=
false
moreButton
.
setImage
(
image
,
forState
:
.
Normal
)
moreButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
...
...
Material.xcodeproj/project.pbxproj
View file @
3e1dc4a4
...
...
@@ -279,22 +279,6 @@
name
=
Switch
;
sourceTree
=
"<group>"
;
};
96A71EF71C71134200C0C4AE
/* Search */
=
{
isa
=
PBXGroup
;
children
=
(
96A71EF51C71127100C0C4AE
/* SearchBarView.swift */
,
);
name
=
Search
;
sourceTree
=
"<group>"
;
};
96A71FB41C764EDB00C0C4AE
/* StatusBar */
=
{
isa
=
PBXGroup
;
children
=
(
96A71FB21C764E3200C0C4AE
/* StatusBarView.swift */
,
);
name
=
StatusBar
;
sourceTree
=
"<group>"
;
};
96A71FB51C764F3D00C0C4AE
/* Control */
=
{
isa
=
PBXGroup
;
children
=
(
...
...
@@ -310,10 +294,6 @@
96D88BFC1C1328D800B91418
/* Info.plist */
,
96D88C091C1328D800B91418
/* Material.h */
,
96D88C501C132A2C00B91418
/* Extensions */
,
96D88C541C132A7700B91418
/* Navigation */
,
96A71FB51C764F3D00C0C4AE
/* Control */
,
96A71FB41C764EDB00C0C4AE
/* StatusBar */
,
96A71EF71C71134200C0C4AE
/* Search */
,
96D88C531C132A6900B91418
/* View */
,
96D88C521C132A5700B91418
/* Layout */
,
96D88C511C132A4200B91418
/* Label */
,
...
...
@@ -330,6 +310,8 @@
965C58BD1C6B8D3300CFB4E1
/* Grid */
,
96A71E921C6FBC2900C0C4AE
/* Menu */
,
96A71EC51C6FFEF300C0C4AE
/* Switch */
,
96A71FB51C764F3D00C0C4AE
/* Control */
,
96D88C541C132A7700B91418
/* Navigation */
,
);
path
=
Sources
;
sourceTree
=
"<group>"
;
...
...
@@ -463,6 +445,8 @@
96D88C541C132A7700B91418
/* Navigation */
=
{
isa
=
PBXGroup
;
children
=
(
96A71FB21C764E3200C0C4AE
/* StatusBarView.swift */
,
96A71EF51C71127100C0C4AE
/* SearchBarView.swift */
,
96D88C151C1328D800B91418
/* NavigationBarView.swift */
,
96A71F2F1C72E41100C0C4AE
/* NavigationBarViewController.swift */
,
96D88C1D1C1328D800B91418
/* SideNavigationViewController.swift */
,
...
...
Sources/ControlView.swift
View file @
3e1dc4a4
...
...
@@ -102,7 +102,7 @@ public class ControlView : MaterialView {
*/
public
convenience
init
?(
leftControls
:
Array
<
UIControl
>
?
=
nil
,
rightControls
:
Array
<
UIControl
>
?
=
nil
)
{
self
.
init
(
frame
:
CGRectMake
(
0
,
0
,
UIScreen
.
mainScreen
()
.
bounds
.
width
,
64
))
prepareProperties
(
leftControls
:
leftControls
,
rightControls
:
rightControls
)
prepareProperties
(
leftControls
,
rightControls
:
rightControls
)
}
public
override
func
layoutSubviews
()
{
...
...
@@ -195,7 +195,7 @@ public class ControlView : MaterialView {
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
internal
func
prepareProperties
(
leftControls
leftControls
:
Array
<
UIControl
>
?,
rightControls
:
Array
<
UIControl
>
?)
{
internal
func
prepareProperties
(
leftControls
:
Array
<
UIControl
>
?,
rightControls
:
Array
<
UIControl
>
?)
{
self
.
leftControls
=
leftControls
self
.
rightControls
=
rightControls
}
...
...
Sources/MaterialSwitch.swift
View file @
3e1dc4a4
...
...
@@ -166,7 +166,30 @@ public class MaterialSwitch: UIControl {
}
/// MaterialSwitch state.
public
private(set)
var
switchState
:
MaterialSwitchState
=
.
Off
public
var
switchState
:
MaterialSwitchState
=
.
Off
{
didSet
{
if
oldValue
!=
switchState
{
userInteractionEnabled
=
false
UIView
.
animateWithDuration
(
0.15
,
delay
:
0.05
,
options
:
.
CurveEaseInOut
,
animations
:
{
[
unowned
self
]
in
self
.
button
.
x
=
.
On
==
self
.
switchState
?
self
.
onPosition
+
self
.
bounceOffset
:
self
.
offPosition
-
self
.
bounceOffset
self
.
styleForState
(
self
.
switchState
)
})
{
[
unowned
self
]
_
in
self
.
styleForState
(
self
.
switchState
)
self
.
sendActionsForControlEvents
(
.
ValueChanged
)
self
.
delegate
?
.
materialSwitchStateChanged
(
self
,
state
:
self
.
switchState
)
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
unowned
self
]
in
self
.
button
.
x
=
.
On
==
self
.
switchState
?
self
.
onPosition
:
self
.
offPosition
})
{
[
unowned
self
]
_
in
self
.
userInteractionEnabled
=
true
}
}
}
}
}
/// MaterialSwitch style.
public
var
switchStyle
:
MaterialSwitchStyle
=
.
LightContent
{
...
...
@@ -290,47 +313,7 @@ public class MaterialSwitch: UIControl {
- Parameter completion: An Optional completion block.
*/
public
func
toggle
(
completion
:
((
control
:
MaterialSwitch
)
->
Void
)?
=
nil
)
{
setSwitchState
(
.
On
==
switchState
?
.
Off
:
.
On
,
animated
:
true
,
completion
:
completion
)
}
/**
Set the switchState property with an option to animate.
- Parameter state: The MaterialSwitchState to set.
- Parameter animated: A Boolean indicating to set the animation or not.
- Parameter completion: An Optional completion block.
*/
public
func
setSwitchState
(
state
:
MaterialSwitchState
,
animated
:
Bool
=
true
,
completion
:
((
control
:
MaterialSwitch
)
->
Void
)?
=
nil
)
{
if
switchState
!=
state
{
if
animated
{
userInteractionEnabled
=
false
UIView
.
animateWithDuration
(
0.15
,
delay
:
0.05
,
options
:
.
CurveEaseInOut
,
animations
:
{
[
unowned
self
]
in
self
.
button
.
x
=
.
On
==
state
?
self
.
onPosition
+
self
.
bounceOffset
:
self
.
offPosition
-
self
.
bounceOffset
self
.
styleForState
(
state
)
})
{
[
unowned
self
]
_
in
self
.
styleForState
(
state
)
self
.
sendActionsForControlEvents
(
.
ValueChanged
)
self
.
switchState
=
state
self
.
delegate
?
.
materialSwitchStateChanged
(
self
,
state
:
state
)
UIView
.
animateWithDuration
(
0.15
,
animations
:
{
[
unowned
self
]
in
self
.
button
.
x
=
.
On
==
state
?
self
.
onPosition
:
self
.
offPosition
})
{
[
unowned
self
]
_
in
self
.
userInteractionEnabled
=
true
completion
?(
control
:
self
)
}
}
}
else
{
button
.
x
=
.
On
==
state
?
self
.
onPosition
:
self
.
offPosition
styleForState
(
state
)
sendActionsForControlEvents
(
.
ValueChanged
)
switchState
=
state
delegate
?
.
materialSwitchStateChanged
(
self
,
state
:
state
)
completion
?(
control
:
self
)
}
}
switchState
=
.
On
==
switchState
?
.
Off
:
.
On
}
/// Handles the TouchUpInside event.
...
...
@@ -348,7 +331,7 @@ public class MaterialSwitch: UIControl {
let
t
:
CGPoint
=
v
.
previousLocationInView
(
sender
)
let
p
:
CGPoint
=
v
.
locationInView
(
sender
)
let
q
:
CGFloat
=
sender
.
x
+
p
.
x
-
t
.
x
s
etSwitchState
(
q
>
(
width
-
button
.
width
)
/
2
?
.
On
:
.
Off
,
animated
:
true
)
s
witchState
=
q
>
(
width
-
button
.
width
)
/
2
?
.
On
:
.
Off
}
}
...
...
@@ -371,7 +354,7 @@ public class MaterialSwitch: UIControl {
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
if
true
==
CGRectContainsPoint
(
trackLayer
.
frame
,
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
))
{
s
etSwitchState
(
.
On
==
switchState
?
.
Off
:
.
On
)
s
witchState
=
.
On
==
switchState
?
.
Off
:
.
On
}
}
...
...
@@ -396,7 +379,7 @@ public class MaterialSwitch: UIControl {
- Parameter state: The MaterialSwitchState to set.
*/
private
func
prepareSwitchState
(
state
:
MaterialSwitchState
)
{
s
etSwitchState
(
state
,
animated
:
false
)
s
witchState
=
state
}
/**
...
...
Sources/NavigationBarView.swift
View file @
3e1dc4a4
...
...
@@ -30,10 +30,6 @@
import
UIKit
@objc(NavigationBarViewDelegate)
public
protocol
NavigationBarViewDelegate
:
StatusBarViewDelegate
{}
public
class
NavigationBarView
:
StatusBarView
{
/// Title label.
public
var
titleLabel
:
UILabel
?
{
...
...
@@ -64,12 +60,14 @@ public class NavigationBarView : StatusBarView {
*/
public
convenience
init
?(
titleLabel
:
UILabel
?
=
nil
,
detailLabel
:
UILabel
?
=
nil
,
leftControls
:
Array
<
UIControl
>
?
=
nil
,
rightControls
:
Array
<
UIControl
>
?
=
nil
)
{
self
.
init
(
frame
:
CGRectMake
(
0
,
0
,
UIScreen
.
mainScreen
()
.
bounds
.
width
,
64
))
prepareProperties
(
titleLabel
:
titleLabel
,
detailLabel
:
detailLabel
,
leftControls
:
leftControls
,
rightControls
:
rightControls
)
prepareProperties
(
titleLabel
,
detailLabel
:
detailLabel
,
leftControls
:
leftControls
,
rightControls
:
rightControls
)
}
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
grid
.
axis
.
columns
=
Int
(
width
/
48
)
// General alignment.
if
UIApplication
.
sharedApplication
()
.
statusBarOrientation
.
isLandscape
{
// TitleView alignment.
...
...
@@ -107,7 +105,6 @@ public class NavigationBarView : StatusBarView {
/// Reloads the view.
public
override
func
reloadView
()
{
super
.
reloadView
()
contentView
.
grid
.
views
=
[]
contentView
.
grid
.
axis
.
rows
=
6
if
let
v
:
UILabel
=
titleLabel
{
...
...
@@ -138,10 +135,9 @@ public class NavigationBarView : StatusBarView {
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
internal
func
prepareProperties
(
titleLabel
titleLabel
:
UILabel
?,
detailLabel
:
UILabel
?,
leftControls
:
Array
<
UIControl
>
?,
rightControls
:
Array
<
UIControl
>
?)
{
prepareProperties
(
leftControls
:
leftControls
,
rightControls
:
rightControls
)
internal
func
prepareProperties
(
titleLabel
:
UILabel
?,
detailLabel
:
UILabel
?,
leftControls
:
Array
<
UIControl
>
?,
rightControls
:
Array
<
UIControl
>
?)
{
prepareProperties
(
leftControls
,
rightControls
:
rightControls
)
self
.
titleLabel
=
titleLabel
self
.
detailLabel
=
detailLabel
}
}
Sources/NavigationBarViewController.swift
View file @
3e1dc4a4
...
...
@@ -161,7 +161,7 @@ public class NavigationBarViewController: UIViewController {
}
}
extension
NavigationBarViewController
:
Navigation
BarViewDelegate
{
extension
NavigationBarViewController
:
Status
BarViewDelegate
{
/// Monitor layout changes.
public
func
statusBarViewDidChangeLayout
(
statusBarView
:
StatusBarView
)
{
layoutSubviews
()
...
...
Sources/StatusBarView.swift
View file @
3e1dc4a4
...
...
@@ -72,11 +72,6 @@ public class StatusBarView : ControlView {
reloadView
()
}
public
override
func
didMoveToSuperview
()
{
super
.
didMoveToSuperview
()
reloadView
()
}
public
override
func
intrinsicContentSize
()
->
CGSize
{
if
UIApplication
.
sharedApplication
()
.
statusBarOrientation
.
isLandscape
{
return
CGSizeMake
(
UIScreen
.
mainScreen
()
.
bounds
.
width
,
44
)
...
...
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