react-native-navigation的迁移库

HMSegmentedControl.h 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // HMSegmentedControl.h
  3. // HMSegmentedControl
  4. //
  5. // Created by Hesham Abd-Elmegid on 23/12/12.
  6. // Copyright (c) 2012-2015 Hesham Abd-Elmegid. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class HMSegmentedControl;
  10. typedef void (^IndexChangeBlock)(NSInteger index);
  11. typedef NSAttributedString *(^HMTitleFormatterBlock)(HMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected);
  12. typedef NS_ENUM(NSInteger, HMSegmentedControlSelectionStyle) {
  13. HMSegmentedControlSelectionStyleTextWidthStripe, // Indicator width will only be as big as the text width
  14. HMSegmentedControlSelectionStyleFullWidthStripe, // Indicator width will fill the whole segment
  15. HMSegmentedControlSelectionStyleBox, // A rectangle that covers the whole segment
  16. HMSegmentedControlSelectionStyleArrow // An arrow in the middle of the segment pointing up or down depending on `HMSegmentedControlSelectionIndicatorLocation`
  17. };
  18. typedef NS_ENUM(NSInteger, HMSegmentedControlSelectionIndicatorLocation) {
  19. HMSegmentedControlSelectionIndicatorLocationUp,
  20. HMSegmentedControlSelectionIndicatorLocationDown,
  21. HMSegmentedControlSelectionIndicatorLocationNone // No selection indicator
  22. };
  23. typedef NS_ENUM(NSInteger, HMSegmentedControlSegmentWidthStyle) {
  24. HMSegmentedControlSegmentWidthStyleFixed, // Segment width is fixed
  25. HMSegmentedControlSegmentWidthStyleDynamic, // Segment width will only be as big as the text width (including inset)
  26. };
  27. typedef NS_OPTIONS(NSInteger, HMSegmentedControlBorderType) {
  28. HMSegmentedControlBorderTypeNone = 0,
  29. HMSegmentedControlBorderTypeTop = (1 << 0),
  30. HMSegmentedControlBorderTypeLeft = (1 << 1),
  31. HMSegmentedControlBorderTypeBottom = (1 << 2),
  32. HMSegmentedControlBorderTypeRight = (1 << 3)
  33. };
  34. enum {
  35. HMSegmentedControlNoSegment = -1 // Segment index for no selected segment
  36. };
  37. typedef NS_ENUM(NSInteger, HMSegmentedControlType) {
  38. HMSegmentedControlTypeText,
  39. HMSegmentedControlTypeImages,
  40. HMSegmentedControlTypeTextImages
  41. };
  42. typedef NS_ENUM(NSInteger, HMSegmentedControlImagePosition) {
  43. HMSegmentedControlImagePositionBehindText,
  44. HMSegmentedControlImagePositionLeftOfText,
  45. HMSegmentedControlImagePositionRightOfText,
  46. HMSegmentedControlImagePositionAboveText,
  47. HMSegmentedControlImagePositionBelowText
  48. };
  49. @interface HMSegmentedControl : UIControl
  50. @property (nonatomic, strong) NSArray<NSString *> *sectionTitles;
  51. @property (nonatomic, strong) NSArray<UIImage *> *sectionImages;
  52. @property (nonatomic, strong) NSArray<UIImage *> *sectionSelectedImages;
  53. /**
  54. Provide a block to be executed when selected index is changed.
  55. Alternativly, you could use `addTarget:action:forControlEvents:`
  56. */
  57. @property (nonatomic, copy) IndexChangeBlock indexChangeBlock;
  58. /**
  59. Used to apply custom text styling to titles when set.
  60. When this block is set, no additional styling is applied to the `NSAttributedString` object returned from this block.
  61. */
  62. @property (nonatomic, copy) HMTitleFormatterBlock titleFormatter;
  63. /**
  64. Text attributes to apply to item title text.
  65. */
  66. @property (nonatomic, strong) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
  67. /*
  68. Text attributes to apply to selected item title text.
  69. Attributes not set in this dictionary are inherited from `titleTextAttributes`.
  70. */
  71. @property (nonatomic, strong) NSDictionary *selectedTitleTextAttributes UI_APPEARANCE_SELECTOR;
  72. /**
  73. Segmented control background color.
  74. Default is `[UIColor whiteColor]`
  75. */
  76. @property (nonatomic, strong) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
  77. /**
  78. Color for the selection indicator stripe
  79. Default is `R:52, G:181, B:229`
  80. */
  81. @property (nonatomic, strong) UIColor *selectionIndicatorColor UI_APPEARANCE_SELECTOR;
  82. /**
  83. Color for the selection indicator box
  84. Default is selectionIndicatorColor
  85. */
  86. @property (nonatomic, strong) UIColor *selectionIndicatorBoxColor UI_APPEARANCE_SELECTOR;
  87. /**
  88. Color for the vertical divider between segments.
  89. Default is `[UIColor blackColor]`
  90. */
  91. @property (nonatomic, strong) UIColor *verticalDividerColor UI_APPEARANCE_SELECTOR;
  92. /**
  93. Opacity for the seletion indicator box.
  94. Default is `0.2f`
  95. */
  96. @property (nonatomic) CGFloat selectionIndicatorBoxOpacity;
  97. /**
  98. Width the vertical divider between segments that is added when `verticalDividerEnabled` is set to YES.
  99. Default is `1.0f`
  100. */
  101. @property (nonatomic, assign) CGFloat verticalDividerWidth;
  102. /**
  103. Specifies the style of the control
  104. Default is `HMSegmentedControlTypeText`
  105. */
  106. @property (nonatomic, assign) HMSegmentedControlType type;
  107. /**
  108. Specifies the style of the selection indicator.
  109. Default is `HMSegmentedControlSelectionStyleTextWidthStripe`
  110. */
  111. @property (nonatomic, assign) HMSegmentedControlSelectionStyle selectionStyle;
  112. /**
  113. Specifies the style of the segment's width.
  114. Default is `HMSegmentedControlSegmentWidthStyleFixed`
  115. */
  116. @property (nonatomic, assign) HMSegmentedControlSegmentWidthStyle segmentWidthStyle;
  117. /**
  118. Specifies the location of the selection indicator.
  119. Default is `HMSegmentedControlSelectionIndicatorLocationUp`
  120. */
  121. @property (nonatomic, assign) HMSegmentedControlSelectionIndicatorLocation selectionIndicatorLocation;
  122. /*
  123. Specifies the border type.
  124. Default is `HMSegmentedControlBorderTypeNone`
  125. */
  126. @property (nonatomic, assign) HMSegmentedControlBorderType borderType;
  127. /**
  128. Specifies the image position relative to the text. Only applicable for HMSegmentedControlTypeTextImages
  129. Default is `HMSegmentedControlImagePositionBehindText`
  130. */
  131. @property (nonatomic) HMSegmentedControlImagePosition imagePosition;
  132. /**
  133. Specifies the distance between the text and the image. Only applicable for HMSegmentedControlTypeTextImages
  134. Default is `0,0`
  135. */
  136. @property (nonatomic) CGFloat textImageSpacing;
  137. /**
  138. Specifies the border color.
  139. Default is `[UIColor blackColor]`
  140. */
  141. @property (nonatomic, strong) UIColor *borderColor;
  142. /**
  143. Specifies the border width.
  144. Default is `1.0f`
  145. */
  146. @property (nonatomic, assign) CGFloat borderWidth;
  147. /**
  148. Default is YES. Set to NO to deny scrolling by dragging the scrollView by the user.
  149. */
  150. @property(nonatomic, getter = isUserDraggable) BOOL userDraggable;
  151. /**
  152. Default is YES. Set to NO to deny any touch events by the user.
  153. */
  154. @property(nonatomic, getter = isTouchEnabled) BOOL touchEnabled;
  155. /**
  156. Default is NO. Set to YES to show a vertical divider between the segments.
  157. */
  158. @property(nonatomic, getter = isVerticalDividerEnabled) BOOL verticalDividerEnabled;
  159. @property (nonatomic, getter=shouldStretchSegmentsToScreenSize) BOOL stretchSegmentsToScreenSize;
  160. /**
  161. Index of the currently selected segment.
  162. */
  163. @property (nonatomic, assign) NSInteger selectedSegmentIndex;
  164. /**
  165. Height of the selection indicator. Only effective when `HMSegmentedControlSelectionStyle` is either `HMSegmentedControlSelectionStyleTextWidthStripe` or `HMSegmentedControlSelectionStyleFullWidthStripe`.
  166. Default is 5.0
  167. */
  168. @property (nonatomic, readwrite) CGFloat selectionIndicatorHeight;
  169. /**
  170. Edge insets for the selection indicator.
  171. NOTE: This does not affect the bounding box of HMSegmentedControlSelectionStyleBox
  172. When HMSegmentedControlSelectionIndicatorLocationUp is selected, bottom edge insets are not used
  173. When HMSegmentedControlSelectionIndicatorLocationDown is selected, top edge insets are not used
  174. Defaults are top: 0.0f
  175. left: 0.0f
  176. bottom: 0.0f
  177. right: 0.0f
  178. */
  179. @property (nonatomic, readwrite) UIEdgeInsets selectionIndicatorEdgeInsets;
  180. /**
  181. Inset left and right edges of segments.
  182. Default is UIEdgeInsetsMake(0, 5, 0, 5)
  183. */
  184. @property (nonatomic, readwrite) UIEdgeInsets segmentEdgeInset;
  185. @property (nonatomic, readwrite) UIEdgeInsets enlargeEdgeInset;
  186. /**
  187. Default is YES. Set to NO to disable animation during user selection.
  188. */
  189. @property (nonatomic) BOOL shouldAnimateUserSelection;
  190. - (id)initWithSectionTitles:(NSArray<NSString *> *)sectiontitles;
  191. - (id)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages;
  192. - (instancetype)initWithSectionImages:(NSArray<UIImage *> *)sectionImages sectionSelectedImages:(NSArray<UIImage *> *)sectionSelectedImages titlesForSections:(NSArray<NSString *> *)sectiontitles;
  193. - (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated;
  194. - (void)setIndexChangeBlock:(IndexChangeBlock)indexChangeBlock;
  195. - (void)setTitleFormatter:(HMTitleFormatterBlock)titleFormatter;
  196. @end