FSSwitchPanel.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #import <UIKit/UIKit.h>
  2. #import "FSSwitchState.h"
  3. @interface FSSwitchPanel : NSObject
  4. + (instancetype)sharedPanel;
  5. @property (nonatomic, readonly, copy) NSArray *switchIdentifiers;
  6. // Returns a list of identifying all switches installed on the device
  7. - (NSString *)titleForSwitchIdentifier:(NSString *)switchIdentifier;
  8. // Returns the localized title for a specific switch
  9. - (UIButton *)buttonForSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle;
  10. // Returns a UIButton for a specific switch
  11. // The button automatically updates its style based on the user interaction and switch state changes, applies the standard action when pressed, and applies the alternate action when held
  12. - (UIImage *)imageOfSwitchState:(FSSwitchState)state controlState:(UIControlState)controlState forSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle;
  13. - (UIImage *)imageOfSwitchState:(FSSwitchState)state controlState:(UIControlState)controlState scale:(CGFloat)scale forSwitchIdentifier:(NSString *)switchIdentifier usingTemplate:(NSBundle *)templateBundle;
  14. // Returns an image representing how a specific switch would look in a particular state when styled with the provided template
  15. - (id)glyphImageDescriptorOfState:(FSSwitchState)switchState size:(CGFloat)size scale:(CGFloat)scale forSwitchIdentifier:(NSString *)switchIdentifier;
  16. // Returns the raw glyph identifier as retrieved from the backing FSSwitch instance
  17. - (FSSwitchState)stateForSwitchIdentifier:(NSString *)switchIdentifier;
  18. // Returns the current state of a particualr switch
  19. - (void)setState:(FSSwitchState)state forSwitchIdentifier:(NSString *)switchIdentifier;
  20. // Updates the state of a particular switch. If the switch accepts the change it will send a state change
  21. - (void)applyActionForSwitchIdentifier:(NSString *)switchIdentifier;
  22. // Applies the default action of a particular switch
  23. - (BOOL)hasAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier;
  24. // Queries whether a switch supports an alternate action. This is often triggered by a hold gesture
  25. - (void)applyAlternateActionForSwitchIdentifier:(NSString *)switchIdentifier;
  26. // Apply the alternate action of a particular switch
  27. - (void)openURLAsAlternateAction:(NSURL *)url;
  28. // Helper method to open a particular URL as if it were launched from an alternate action
  29. @end
  30. @protocol FSSwitchDataSource;
  31. @interface FSSwitchPanel (SpringBoard)
  32. - (void)registerDataSource:(id<FSSwitchDataSource>)dataSource forSwitchIdentifier:(NSString *)switchIdentifier;
  33. // Registers a switch implementation for a specific identifier. Bundlee in /Library/Switches will have their principal class automatically loaded
  34. - (void)unregisterSwitchIdentifier:(NSString *)switchIdentifier;
  35. // Unregisters a switch
  36. - (void)stateDidChangeForSwitchIdentifier:(NSString *)switchIdentifier;
  37. // Informs the system when a switch changes its state. This will trigger any switch buttons to update their style
  38. @end
  39. extern NSString * const FSSwitchPanelSwitchesChangedNotification;
  40. extern NSString * const FSSwitchPanelSwitchStateChangedNotification;
  41. extern NSString * const FSSwitchPanelSwitchIdentifierKey;
  42. extern NSString * const FSSwitchPanelSwitchWillOpenURLNotification;