fakes.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // fakes.h
  3. // FLEX
  4. //
  5. // Created by Kevin Bradley on 12/22/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @protocol UIFakePickerViewDataSource, UIFakePickerViewDelegate;
  10. @interface UIFakePickerView : UIView <NSCoding>
  11. @property(nullable,nonatomic,weak) id<UIFakePickerViewDataSource> dataSource; // default is nil. weak reference
  12. @property(nullable,nonatomic,weak) id<UIFakePickerViewDelegate> delegate; // default is nil. weak reference
  13. @property(nonatomic) BOOL showsSelectionIndicator API_DEPRECATED("This property has no effect on iOS 7 and later.", ios(2.0, 13.0));
  14. // info that was fetched and cached from the data source and delegate
  15. @property(nonatomic,readonly) NSInteger numberOfComponents;
  16. - (NSInteger)numberOfRowsInComponent:(NSInteger)component;
  17. - (CGSize)rowSizeForComponent:(NSInteger)component;
  18. // returns the view provided by the delegate via pickerView:viewForRow:forComponent:reusingView:
  19. // or nil if the row/component is not visible or the delegate does not implement
  20. // pickerView:viewForRow:forComponent:reusingView:
  21. - (nullable UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
  22. // Reloading whole view or single component
  23. - (void)reloadAllComponents;
  24. - (void)reloadComponent:(NSInteger)component;
  25. // selection. in this case, it means showing the appropriate row in the middle
  26. - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; // scrolls the specified row to center.
  27. - (NSInteger)selectedRowInComponent:(NSInteger)component; // returns selected row. -1 if nothing selected
  28. @end
  29. @protocol UIFakePickerViewDataSource<NSObject>
  30. @required
  31. // returns the number of 'columns' to display.
  32. - (NSInteger)numberOfComponentsInPickerView:(UIFakePickerView *_Nonnull)pickerView;
  33. // returns the # of rows in each component..
  34. - (NSInteger)pickerView:(UIFakePickerView *_Nonnull)pickerView numberOfRowsInComponent:(NSInteger)component;
  35. @end
  36. @protocol UIFakePickerViewDelegate<NSObject>
  37. @optional
  38. // returns width of column and height of row for each component.
  39. - (CGFloat)pickerView:(UIFakePickerView *_Nonnull)pickerView widthForComponent:(NSInteger)component ;
  40. - (CGFloat)pickerView:(UIFakePickerView *_Nonnull)pickerView rowHeightForComponent:(NSInteger)component ;
  41. // these methods return either a plain NSString, a NSAttributedString, or a view (e.g UILabel) to display the row for the component.
  42. // for the view versions, we cache any hidden and thus unused views and pass them back for reuse.
  43. // If you return back a different object, the old one will be released. the view will be centered in the row rect
  44. - (nullable NSString *)pickerView:(UIFakePickerView *_Nonnull)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component ;
  45. - (nullable NSAttributedString *)pickerView:(UIFakePickerView *_Nonnull)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component API_AVAILABLE(ios(6.0)) ; // attributed title is favored if both methods are implemented
  46. - (UIView *_Nonnull)pickerView:(UIFakePickerView *_Nonnull)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view ;
  47. - (void)pickerView:(UIFakePickerView *_Nonnull)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component ;
  48. @end
  49. @interface UIFakeSwitch : UIControl <NSCoding>
  50. @property(nullable, nonatomic, strong) UIColor *onTintColor;
  51. @property(nullable, nonatomic, strong) UIColor *thumbTintColor;
  52. @property(nullable, nonatomic, strong) UIImage *onImage;
  53. @property(nullable, nonatomic, strong) UIImage *offImage;
  54. @property(nonatomic,getter=isOn) BOOL on;
  55. - (instancetype _Nonnull )initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER; // This class enforces a size appropriate for the control, and so the frame size is ignored.
  56. - (nullable instancetype)initWithCoder:(NSCoder *_Nonnull)coder NS_DESIGNATED_INITIALIZER;
  57. - (void)setOn:(BOOL)on animated:(BOOL)animated; // does not send action
  58. @end
  59. @interface UIFakeSlider: UIControl <NSCoding>
  60. @property(nonatomic) float value;
  61. @property(nonatomic) float minimumValue;
  62. @property(nonatomic) float maximumValue;
  63. @property(nonatomic) float minValue;
  64. @property(nonatomic) float maxValue;
  65. @property(nonatomic) float allowedMinValue;
  66. @property(nonatomic) float allowedMaxValue;
  67. @property(nullable, nonatomic,strong) UIImage *minimumValueImage;
  68. @property(nullable, nonatomic,strong) UIImage *maximumValueImage;
  69. @property(nonatomic,getter=isContinuous) BOOL continuous;
  70. @property(nullable, nonatomic,strong) UIColor *minimumTrackTintColor;
  71. @property(nullable, nonatomic,strong) UIColor *maximumTrackTintColor;
  72. @property(nullable, nonatomic,strong) UIColor *thumbTintColor;
  73. - (void)setValue:(float)value animated:(BOOL)animated;
  74. - (void)setThumbImage:(nullable UIImage *)image forState:(UIControlState)state;
  75. - (void)setMinimumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
  76. - (void)setMaximumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
  77. - (nullable UIImage *)thumbImageForState:(UIControlState)state;
  78. - (nullable UIImage *)minimumTrackImageForState:(UIControlState)state;
  79. - (nullable UIImage *)maximumTrackImageForState:(UIControlState)state;
  80. @property(nullable,nonatomic,readonly) UIImage *currentThumbImage;
  81. @property(nullable,nonatomic,readonly) UIImage *currentMinimumTrackImage;
  82. @property(nullable,nonatomic,readonly) UIImage *currentMaximumTrackImage;
  83. // lets a subclass lay out the track and thumb as needed
  84. - (CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
  85. - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds;
  86. - (CGRect)trackRectForBounds:(CGRect)bounds;
  87. - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;
  88. @end