-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathJTMaterialSwitch.h
More file actions
143 lines (126 loc) · 5.58 KB
/
Copy pathJTMaterialSwitch.h
File metadata and controls
143 lines (126 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// JTMaterialSwitch.h
// JTMaterialSwitch
//
// Created by Junichi Tsurukawa on 2015/09/06.
//
// The MIT License (MIT)
// Copyright (c) 2015 Junichi Tsurukawa. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
#pragma mark - Switch type
typedef enum {
JTMaterialSwitchStyleLight,
JTMaterialSwitchStyleDark,
JTMaterialSwitchStyleDefault
} JTMaterialSwitchStyle;
#pragma mark - Initial state (on or off)
typedef enum {
JTMaterialSwitchStateOn,
JTMaterialSwitchStateOff
} JTMaterialSwitchState;
#pragma mark - Initial JTMaterialSwitch size (big, normal, small)
typedef enum {
JTMaterialSwitchSizeBig,
JTMaterialSwitchSizeNormal,
JTMaterialSwitchSizeSmall
} JTMaterialSwitchSize;
@protocol JTMaterialSwitchDelegate <NSObject>
// Delegate method
- (void)switchStateChanged:(JTMaterialSwitchState)currentState;
@end
@interface JTMaterialSwitch : UIControl
#pragma mark - Properties
#pragma Delegate
@property (nonatomic, assign) id<JTMaterialSwitchDelegate> delegate;
#pragma State
/** A Boolean value that represents switch's current state(ON/OFF). YES to ON, NO to OFF the switch */
@property (nonatomic) BOOL isOn;
/** A Boolean value that represents switch's interaction mode. YES to set enabled, No to set disabled*/
@property (nonatomic) BOOL isEnabled;
/** A Boolean value whether the bounce animation effect is enabled when state change movement */
@property (nonatomic) BOOL isBounceEnabled;
/** A Boolean value whether the ripple animation effect is enabled or not */
@property (nonatomic) BOOL isRippleEnabled;
#pragma Colour
/** An UIColor property to represent the colour of the switch thumb when position is ON */
@property (nonatomic, strong) UIColor *thumbOnTintColor;
/** An UIColor property to represent the colour of the switch thumb when position is OFF */
@property (nonatomic, strong) UIColor *thumbOffTintColor;
/** An UIColor property to represent the colour of the track when position is ON */
@property (nonatomic, strong) UIColor *trackOnTintColor;
/** An UIColor property to represent the colour of the track when position is OFF */
@property (nonatomic, strong) UIColor *trackOffTintColor;
/** An UIColor property to represent the colour of the switch thumb when position is DISABLED */
@property (nonatomic, strong) UIColor *thumbDisabledTintColor;
/** An UIColor property to represent the colour of the track when position is DISABLED */
@property (nonatomic, strong) UIColor *trackDisabledTintColor;
/** An UIColor property to represent the fill colour of the ripple only when ripple effect is enabled */
@property (nonatomic, strong) UIColor *rippleFillColor;
#pragma UI components
/** An UIButton object that represents current state(ON/OFF) */
@property (nonatomic, strong) UIButton *switchThumb;
/** An UIView object that represents the track for the thumb */
@property (nonatomic, strong) UIView *track;
#pragma mark - Initializer
/**
* Initializes a JTMaterialSwitch in the easiest way with default parameters.
*
* @JTMaterialSwitchStyle: JTMaterialSwitchStyleDefault,
* @JTMaterialSwitchState: JTMaterialSwitchStateOn,
* @JTMaterialSwitchSize: JTMaterialSwitchSizeNormal
*
* @return A JTFadingInfoView with above parameters
*/
- (id)init;
/**
* Initializes a JTMaterialSwitch with a initial switch state position and size.
*
* @param size A JTMaterialSwitchSize enum as this view's size(big, normal, small)
* @param state A JTMaterialSwitchState enum as this view's initial switch pos(ON/OFF)
*
* @return A JTFadingInfoView with size and initial position
*/
- (id)initWithSize:(JTMaterialSwitchSize)size state:(JTMaterialSwitchState)state;
/**
* Initializes a JTMaterialSwitch with a initial switch size, style and state.
*
* @param size A JTMaterialSwitchSize enum as this view's size(big, normal, small)
* @param state A JTMaterialSwitchStyle enum as this view's initial style
* @param state A JTMaterialSwitchState enum as this view's initial switch pos(ON/OFF)
*
* @return A JTFadingInfoView with size, style and initial position
*/
- (id)initWithSize:(JTMaterialSwitchSize)size style:(JTMaterialSwitchStyle)style state:(JTMaterialSwitchState)state;
#pragma setter/getter
/**
* Initializes a JTMaterialSwitch with a initial switch size, style and state.
*
* @return A boolean value. Yes if the current switch state is ON, NO if OFF.
*/
- (BOOL)getSwitchState;
/**
* Set switch state with or without moving animation of switch thumb
*
* @param on The switch state you want to set
* @param animated Yes to set with animation, NO to do without.
*/
- (void)setOn:(BOOL)on animated:(BOOL)animated;
@end