fakes.h 5.7 KB

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