CustomSwitch.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // CustomSwitch.h
  3. // JasonDevelop
  4. //
  5. // source : https://github.com/KieranLafferty/KLSwitch
  6. //
  7. // Created by Jason Lee on 3/11/14.
  8. // Copyright (c) jasondevelop. All rights reserved.
  9. //
  10. @import UIKit;
  11. @import QuartzCore;
  12. #define LOCK_IMAGE_SUBVIEW 100
  13. typedef void(^changeHandler)(BOOL isOn);
  14. @interface CustomSwitch : UIControl <NSCoding>
  15. //UISwitch interface
  16. @property(nonatomic, strong) UIImage *onImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //Currently this does nothing
  17. @property(nonatomic, strong) UIImage *offImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //Currently this does nothing
  18. @property(nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
  19. @property(nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
  20. @property(nonatomic, strong) UIColor *thumbTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
  21. ///Additional color options provided by KLSwitch only
  22. @property(nonatomic, strong) UIColor *contrastColor;
  23. @property(nonatomic, strong) UIColor *thumbBorderColor;
  24. @property(nonatomic, getter=isOn) BOOL on;
  25. @property(nonatomic, getter=isLocked) BOOL locked;
  26. //Custom completion block initiated by value change (on/off)
  27. @property(nonatomic, copy) changeHandler didChangeHandler;
  28. //Percent (0.0 - 1.0) of the control to travel while panning before a switch toggle is activated
  29. @property(nonatomic, assign) CGFloat panActivationThreshold;
  30. //Set to true if you want to maintain 51x31 proportions, false if you want to set the frame to anything
  31. @property(nonatomic, assign) BOOL shouldConstrainFrame;
  32. //Initializers
  33. - (id)initWithFrame:(CGRect)frame;
  34. - (id)initWithFrame:(CGRect)frame
  35. didChangeHandler:(changeHandler) didChangeHandler;
  36. //Events
  37. - (void)setOn:(BOOL)on animated:(BOOL)animated;
  38. - (void)setLocked:(BOOL)locked;
  39. @end