PGPickerView.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // PGPickerView.h
  3. // PGPickerView
  4. //
  5. // Created by piggybear on 2017/7/26.
  6. // Copyright © 2017年 piggybear. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. typedef NS_ENUM(NSUInteger, PGPickerViewType) {
  10. PGPickerViewType1,
  11. PGPickerViewType2,
  12. PGPickerViewType3,
  13. };
  14. @protocol PGPickerViewDataSource, PGPickerViewDelegate;
  15. @interface PGPickerView : UIView
  16. @property(nonatomic, assign) PGPickerViewType type;
  17. @property(nonatomic,weak) id<PGPickerViewDataSource> dataSource; // default is nil. weak reference
  18. @property(nonatomic,weak) id<PGPickerViewDelegate> delegate; // default is nil. weak reference
  19. @property(nonatomic, strong) UIColor *lineBackgroundColor; // default is [UIColor grayColor]
  20. @property (nonatomic, assign) CGFloat lineHeight; // default is 0.5
  21. @property(nonatomic, strong) UIColor *verticalLineBackgroundColor; // default is [UIColor grayColor] type3 vertical line
  22. @property (nonatomic, assign) CGFloat verticalLineWidth; // default is 0.5
  23. @property (nonatomic, strong)UIColor *textColorOfSelectedRow; // [UIColor blackColor]
  24. @property(nonatomic, strong) UIFont *textFontOfSelectedRow;
  25. @property (nonatomic, strong)UIColor *textColorOfOtherRow; // default is [UIColor grayColor]
  26. @property(nonatomic, strong) UIFont *textFontOfOtherRow;
  27. // info that was fetched and cached from the data source and delegate
  28. @property(nonatomic,readonly) NSInteger numberOfComponents;
  29. @property (nonatomic) CGFloat rowHeight; // default is 44
  30. @property(nonatomic, assign) BOOL isHiddenMiddleText; // default is true true -> hidden
  31. @property(nonatomic, strong) UIColor *middleTextColor;
  32. @property(nonatomic, strong) UIFont *middleTextFont;
  33. @property(nonatomic, assign) BOOL isHiddenWheels; // default is true true -> hidden
  34. - (NSInteger)numberOfRowsInComponent:(NSInteger)component;
  35. // selection. in this case, it means showing the appropriate row in the middle
  36. - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;// scrolls the specified row to center.
  37. - (NSInteger)selectedRowInComponent:(NSInteger)component;// returns selected row. -1 if nothing selected
  38. - (NSString *)textOfSelectedRowInComponent:(NSInteger)component;
  39. // Reloading whole view or single component
  40. - (void)reloadAllComponents;
  41. - (void)reloadComponent:(NSInteger)component;
  42. - (void)reloadComponent:(NSInteger)component refresh:(BOOL)refresh;
  43. @end
  44. @protocol PGPickerViewDataSource<NSObject>
  45. @required
  46. // returns the number of 'columns' to display.
  47. - (NSInteger)numberOfComponentsInPickerView:(PGPickerView *)pickerView;
  48. // returns the # of rows in each component..
  49. - (NSInteger)pickerView:(PGPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
  50. @end
  51. @protocol PGPickerViewDelegate<NSObject>
  52. @optional
  53. // these methods return either a plain NSString, a NSAttributedString, or a view (e.g UILabel) to display the row for the component.
  54. // for the view versions, we cache any hidden and thus unused views and pass them back for reuse.
  55. // If you return back a different object, the old one will be released. the view will be centered in the row rect
  56. - (NSString *)pickerView:(PGPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
  57. - (NSAttributedString *)pickerView:(PGPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component; // attributed title is favored if both methods are implemented
  58. - (UIColor *)pickerView:(PGPickerView *)pickerView viewBackgroundColorForRow:(NSInteger)row forComponent:(NSInteger)component;
  59. - (void)pickerView:(PGPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
  60. - (void)pickerView:(PGPickerView *)pickerView title:(NSString *)title didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
  61. - (CGFloat)rowHeightInPickerView:(PGPickerView *)pickerView forComponent:(NSInteger)component;
  62. - (NSString *)pickerView:(PGPickerView *)pickerView middleTextForcomponent:(NSInteger)component;
  63. - (CGFloat)pickerView:(PGPickerView *)pickerView middleTextSpaceForcomponent:(NSInteger)component;
  64. // type is PGPickerViewType3 vertical line
  65. - (UIColor *)pickerView:(PGPickerView *)pickerView verticalLineBackgroundColorForComponent:(NSInteger)component;
  66. - (CGFloat)pickerView:(PGPickerView *)pickerView verticalLineWidthForComponent:(NSInteger)component;
  67. - (UIColor *)pickerView:(PGPickerView *)pickerView upLineBackgroundColorForComponent:(NSInteger)component;
  68. - (UIColor *)pickerView:(PGPickerView *)pickerView downLineBackgroundColorForComponent:(NSInteger)component;
  69. - (CGFloat)pickerView:(PGPickerView *)pickerView upLineHeightForComponent:(NSInteger)component;
  70. - (CGFloat)pickerView:(PGPickerView *)pickerView downLineHeightForComponent:(NSInteger)component;
  71. - (UIFont *)pickerView:(PGPickerView *)pickerView textFontOfSelectedRowInComponent:(NSInteger)component;
  72. - (UIFont *)pickerView:(PGPickerView *)pickerView textFontOfOtherRowInComponent:(NSInteger)component;
  73. - (UIColor *)pickerView:(PGPickerView *)pickerView textColorOfSelectedRowInComponent:(NSInteger)component;
  74. - (UIColor *)pickerView:(PGPickerView *)pickerView textColorOfOtherRowInComponent:(NSInteger)component;
  75. - (UIFont *)pickerView:(PGPickerView *)pickerView textFontOfOtherRow:(NSInteger)row InComponent:(NSInteger)component;
  76. - (UIColor *)pickerView:(PGPickerView *)pickerView textColorOfOtherRow:(NSInteger)row InComponent:(NSInteger)component;
  77. @end