123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // RQSwitch.h
- // jiaPei
- //
- // Created by 张嵘 on 2022/4/27.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #pragma mark - Switch type
- typedef enum {
- RQSwitchStyleLight,
- RQSwitchStyleDark,
- RQSwitchStyleDefault,
- RQSwitchStyleSubject,
- } RQSwitchStyle;
- #pragma mark - Initial state (on or off)
- typedef enum {
- RQSwitchStateOn,
- RQSwitchStateOff,
- } RQSwitchState;
- #pragma mark - Initial RQSwitch size (big, normal, small)
- typedef enum {
- RQSwitchSizeBig,
- RQSwitchSizeNormal,
- RQSwitchSizeSmall,
- RQSwitchSizeSubject,
- } RQSwitchSize;
- @protocol RQSwitchDelegate <NSObject>
- // Delegate method
- - (void)switchStateChanged:(RQSwitchState)currentState;
- @end
- @interface RQSwitch : UIControl
- #pragma mark - Properties
- #pragma Delegate
- @property (nonatomic, assign) id<RQSwitchDelegate> 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;
- @property (nonatomic, readwrite, strong) UILabel *trackLeftLabel;
- @property (nonatomic, readwrite, strong) UILabel *trackRightLabel;
- @property (nonatomic, readwrite, assign) CGSize trackSize;
- @property (nonatomic, readwrite, assign) CGSize thumbSize;
- @property (nonatomic, readwrite, copy) NSString *trackStr;
- @property (nonatomic, readwrite, copy) NSString *thumbStr;
- #pragma mark - Initializer
- /**
- * Initializes a RQSwitch in the easiest way with default parameters.
- *
- * @RQSwitchStyle: RQSwitchStyleDefault,
- * @RQSwitchState: RQSwitchStateOn,
- * @RQSwitchSize: RQSwitchSizeNormal
- *
- * @return A JTFadingInfoView with above parameters
- */
- - (id)init;
- /**
- * Initializes a RQSwitch with a initial switch state position and size.
- *
- * @param size A RQSwitchSize enum as this view's size(big, normal, small)
- * @param state A RQSwitchState enum as this view's initial switch pos(ON/OFF)
- *
- * @return A JTFadingInfoView with size and initial position
- */
- - (id)initWithSize:(RQSwitchSize)size state:(RQSwitchState)state;
- /**
- * Initializes a RQSwitch with a initial switch size, style and state.
- *
- * @param size A RQSwitchSize enum as this view's size(big, normal, small)
- * @param state A RQSwitchStyle enum as this view's initial style
- * @param state A RQSwitchState enum as this view's initial switch pos(ON/OFF)
- *
- * @return A JTFadingInfoView with size, style and initial position
- */
- - (id)initWithSize:(RQSwitchSize)size style:(RQSwitchStyle)style state:(RQSwitchState)state;
- #pragma setter/getter
- /**
- * Initializes a RQSwitch 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
|