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
d6bee85d
Unverified
Commit
d6bee85d
authored
Apr 18, 2019
by
Daniel Jonathan
Committed by
GitHub
Apr 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1221 from OrkhanAlikhanov/switch-668
Made Switch more customizable
parents
22462d97
4bdd8f05
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
5 deletions
+54
-5
Sources/iOS/Switch/Switch.swift
+54
-5
No files found.
Sources/iOS/Switch/Switch.swift
View file @
d6bee85d
...
...
@@ -36,11 +36,11 @@ public enum SwitchState: Int {
case
off
}
@objc(SwitchSize)
public
enum
SwitchSize
:
Int
{
public
enum
SwitchSize
{
case
small
case
medium
case
large
case
custom
(
width
:
CGFloat
,
height
:
CGFloat
)
}
@objc(SwitchDelegate)
...
...
@@ -63,10 +63,18 @@ open class Switch: UIControl, Themeable {
fileprivate
var
internalSwitchState
=
SwitchState
.
off
/// Track thickness.
fileprivate
var
trackThickness
:
CGFloat
=
0
open
var
trackThickness
:
CGFloat
=
0
{
didSet
{
layoutSubviews
()
}
}
/// Button diameter.
fileprivate
var
buttonDiameter
:
CGFloat
=
0
open
var
buttonDiameter
:
CGFloat
=
0
{
didSet
{
layoutSubviews
()
}
}
/// Position when in the .on state.
fileprivate
var
onPosition
:
CGFloat
=
0
...
...
@@ -104,6 +112,22 @@ open class Switch: UIControl, Themeable {
}
}
/// Button on image.
@IBInspectable
open
var
buttonOnImage
:
UIImage
?
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Button off image.
@IBInspectable
open
var
buttonOffImage
:
UIImage
?
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track on color.
@IBInspectable
open
var
trackOnColor
=
Color
.
clear
{
...
...
@@ -152,6 +176,23 @@ open class Switch: UIControl, Themeable {
}
}
/// Button on disabled image.
@IBInspectable
open
var
buttonOnDisabledImage
:
UIImage
?
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Button off disabled image.
@IBInspectable
open
var
buttonOffDisabledImage
:
UIImage
?
{
didSet
{
styleForState
(
state
:
switchState
)
}
}
/// Track view reference.
open
fileprivate
(
set
)
var
track
:
UIView
{
didSet
{
...
...
@@ -207,9 +248,11 @@ open class Switch: UIControl, Themeable {
case
.
large
:
trackThickness
=
24
buttonDiameter
=
28
case
.
custom
:
break
}
frame
.
size
=
intrinsicContentSize
invalidateIntrinsicContentSize
()
}
}
...
...
@@ -221,6 +264,8 @@ open class Switch: UIControl, Themeable {
return
CGSize
(
width
:
38
,
height
:
38
)
case
.
large
:
return
CGSize
(
width
:
42
,
height
:
42
)
case
.
custom
(
let
width
,
let
height
):
return
CGSize
(
width
:
width
,
height
:
height
)
}
}
...
...
@@ -408,9 +453,11 @@ fileprivate extension Switch {
if
.
on
==
state
{
button
.
backgroundColor
=
buttonOnColor
track
.
backgroundColor
=
trackOnColor
button
.
image
=
buttonOnImage
}
else
{
button
.
backgroundColor
=
buttonOffColor
track
.
backgroundColor
=
trackOffColor
button
.
image
=
buttonOffImage
}
}
...
...
@@ -422,9 +469,11 @@ fileprivate extension Switch {
if
.
on
==
state
{
button
.
backgroundColor
=
buttonOnDisabledColor
track
.
backgroundColor
=
trackOnDisabledColor
button
.
image
=
buttonOnDisabledImage
}
else
{
button
.
backgroundColor
=
buttonOffDisabledColor
track
.
backgroundColor
=
trackOffDisabledColor
button
.
image
=
buttonOffDisabledImage
}
}
...
...
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