RQSwitch.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // RQSwitch.h
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/4/27.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #pragma mark - Switch type
  10. typedef enum {
  11. RQSwitchStyleLight,
  12. RQSwitchStyleDark,
  13. RQSwitchStyleDefault,
  14. RQSwitchStyleSubject,
  15. } RQSwitchStyle;
  16. #pragma mark - Initial state (on or off)
  17. typedef enum {
  18. RQSwitchStateOn,
  19. RQSwitchStateOff,
  20. } RQSwitchState;
  21. #pragma mark - Initial RQSwitch size (big, normal, small)
  22. typedef enum {
  23. RQSwitchSizeBig,
  24. RQSwitchSizeNormal,
  25. RQSwitchSizeSmall,
  26. RQSwitchSizeSubject,
  27. } RQSwitchSize;
  28. @protocol RQSwitchDelegate <NSObject>
  29. // Delegate method
  30. - (void)switchStateChanged:(RQSwitchState)currentState;
  31. @end
  32. @interface RQSwitch : UIControl
  33. #pragma mark - Properties
  34. #pragma Delegate
  35. @property (nonatomic, assign) id<RQSwitchDelegate> delegate;
  36. #pragma State
  37. /** A Boolean value that represents switch's current state(ON/OFF). YES to ON, NO to OFF the switch */
  38. @property (nonatomic) BOOL isOn;
  39. /** A Boolean value that represents switch's interaction mode. YES to set enabled, No to set disabled*/
  40. @property (nonatomic) BOOL isEnabled;
  41. /** A Boolean value whether the bounce animation effect is enabled when state change movement */
  42. @property (nonatomic) BOOL isBounceEnabled;
  43. /** A Boolean value whether the ripple animation effect is enabled or not */
  44. @property (nonatomic) BOOL isRippleEnabled;
  45. #pragma Colour
  46. /** An UIColor property to represent the colour of the switch thumb when position is ON */
  47. @property (nonatomic, strong) UIColor *thumbOnTintColor;
  48. /** An UIColor property to represent the colour of the switch thumb when position is OFF */
  49. @property (nonatomic, strong) UIColor *thumbOffTintColor;
  50. /** An UIColor property to represent the colour of the track when position is ON */
  51. @property (nonatomic, strong) UIColor *trackOnTintColor;
  52. /** An UIColor property to represent the colour of the track when position is OFF */
  53. @property (nonatomic, strong) UIColor *trackOffTintColor;
  54. /** An UIColor property to represent the colour of the switch thumb when position is DISABLED */
  55. @property (nonatomic, strong) UIColor *thumbDisabledTintColor;
  56. /** An UIColor property to represent the colour of the track when position is DISABLED */
  57. @property (nonatomic, strong) UIColor *trackDisabledTintColor;
  58. /** An UIColor property to represent the fill colour of the ripple only when ripple effect is enabled */
  59. @property (nonatomic, strong) UIColor *rippleFillColor;
  60. #pragma UI components
  61. /** An UIButton object that represents current state(ON/OFF) */
  62. @property (nonatomic, strong) UIButton *switchThumb;
  63. /** An UIView object that represents the track for the thumb */
  64. @property (nonatomic, strong) UIView *track;
  65. @property (nonatomic, readwrite, strong) UILabel *trackLeftLabel;
  66. @property (nonatomic, readwrite, strong) UILabel *trackRightLabel;
  67. @property (nonatomic, readwrite, assign) CGSize trackSize;
  68. @property (nonatomic, readwrite, assign) CGSize thumbSize;
  69. @property (nonatomic, readwrite, copy) NSString *trackStr;
  70. @property (nonatomic, readwrite, copy) NSString *thumbStr;
  71. #pragma mark - Initializer
  72. /**
  73. * Initializes a RQSwitch in the easiest way with default parameters.
  74. *
  75. * @RQSwitchStyle: RQSwitchStyleDefault,
  76. * @RQSwitchState: RQSwitchStateOn,
  77. * @RQSwitchSize: RQSwitchSizeNormal
  78. *
  79. * @return A JTFadingInfoView with above parameters
  80. */
  81. - (id)init;
  82. /**
  83. * Initializes a RQSwitch with a initial switch state position and size.
  84. *
  85. * @param size A RQSwitchSize enum as this view's size(big, normal, small)
  86. * @param state A RQSwitchState enum as this view's initial switch pos(ON/OFF)
  87. *
  88. * @return A JTFadingInfoView with size and initial position
  89. */
  90. - (id)initWithSize:(RQSwitchSize)size state:(RQSwitchState)state;
  91. /**
  92. * Initializes a RQSwitch with a initial switch size, style and state.
  93. *
  94. * @param size A RQSwitchSize enum as this view's size(big, normal, small)
  95. * @param state A RQSwitchStyle enum as this view's initial style
  96. * @param state A RQSwitchState enum as this view's initial switch pos(ON/OFF)
  97. *
  98. * @return A JTFadingInfoView with size, style and initial position
  99. */
  100. - (id)initWithSize:(RQSwitchSize)size style:(RQSwitchStyle)style state:(RQSwitchState)state;
  101. #pragma setter/getter
  102. /**
  103. * Initializes a RQSwitch with a initial switch size, style and state.
  104. *
  105. * @return A boolean value. Yes if the current switch state is ON, NO if OFF.
  106. */
  107. - (BOOL)getSwitchState;
  108. /**
  109. * Set switch state with or without moving animation of switch thumb
  110. *
  111. * @param on The switch state you want to set
  112. * @param animated Yes to set with animation, NO to do without.
  113. */
  114. - (void)setOn:(BOOL)on animated:(BOOL)animated;
  115. @end