WNSegmentControl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // WNSegmentControl.h
  3. #import <UIKit/UIKit.h>
  4. /// 指示器位置
  5. typedef NS_ENUM(NSUInteger, WNSegmentedControlIndicatorLocate) {
  6. WNSegmentedControlIndicatorLocateTop,
  7. WNSegmentedControlIndicatorLocateBottom,
  8. };
  9. /// 指示器宽度风格
  10. typedef NS_ENUM(NSUInteger, WNSegmentedControlIndicatorWidthStyle) {
  11. WNSegmentedControlIndicatorWidthStyleFull,
  12. WNSegmentedControlIndicatorWidthStyleText,
  13. WNSegmentedControlIndicatorWidthStyleShort,
  14. };
  15. typedef NS_ENUM(NSInteger, WNSegmentedControlWidthStyle) {
  16. WNSegmentedControlWidthStyleFixed, // 平均分割
  17. WNSegmentedControlWidthStyleDynamic, // 同字体宽度
  18. };
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface WNSegmentControl :UIControl
  21. ///---------------------
  22. /// @name Initialization
  23. ///---------------------
  24. - (instancetype)initWithTitles:(NSArray <NSString *> *)titles;
  25. - (instancetype)initWithImages:(NSArray <UIImage *> *)images;
  26. - (instancetype)initWithImages:(NSArray <UIImage *> *)images
  27. selectedImages:(nullable NSArray <UIImage *> *)selectedImages;
  28. - (instancetype)initWithAttributedTitles:(NSArray <NSAttributedString *> *)titles;
  29. - (nullable NSString *)titleAtIndex:(NSUInteger)index;
  30. - (nullable UIImage *)imageAtIndex:(NSUInteger)index;
  31. - (void)setTitle:(NSString *)title atIndex:(NSUInteger)index;
  32. - (void)setImage:(UIImage *)image atIndex:(NSUInteger)index;
  33. - (void)setImage:(UIImage *)image selectedImage:(nullable UIImage *)selectedImage atIndex:(NSUInteger)index;
  34. - (void)insertTitle:(NSString *)title atIndex:(NSUInteger)index;
  35. - (void)removeTitleAtIndex:(NSUInteger)index;
  36. - (void)setTitles:(NSArray<NSString *> *)titles;
  37. - (void)setTextAttributes:(nullable NSDictionary *)attributes forState:(UIControlState)state;
  38. - (void)setSelectedSegmentIndex:(NSUInteger)selectedSegmentIndex ignoreAction:(BOOL)ignoreAction;
  39. - (void)addTipViewWithGenerator:(UIView *(^)(NSUInteger index))viewGenerator;
  40. - (void)reloadData;
  41. @property (nonatomic, assign, readonly) NSUInteger numberOfSegments;
  42. @property (nonatomic, assign) NSUInteger selectedSegmentIndex;
  43. @property (nonatomic, assign) WNSegmentedControlWidthStyle widthStyle;
  44. @property (nonatomic, readwrite) UIEdgeInsets segmentEdgeInset;
  45. /**
  46. The padding(including left and right) at which the origin of the contents is offset from the origin of the segmented control. Default is 0.
  47. */
  48. @property (nonatomic, assign) CGFloat horizontalPadding;
  49. /**
  50. A Boolean value that controls whether the top separator is visible. Default is `NO`.
  51. */
  52. @property (nonatomic, assign, getter=isShowsTopSeparator) BOOL showsTopSeparator;
  53. /**
  54. A Boolean value that controls whether the item separator is visible. Default is `NO`.
  55. */
  56. @property (nonatomic, assign, getter=isShowsItemSeparator) BOOL showsItemSeparator;
  57. /**
  58. A Boolean value that controls whether the bottom separator is visible. Default is `NO`.
  59. */
  60. @property (nonatomic, assign, getter=isShowsBottomSeparator) BOOL showsBottomSeparator;
  61. /**
  62. A Boolean value that controls whether the bottom shadow is visible. Default is `NO`.
  63. */
  64. @property (nonatomic, assign, getter=isShowBottomShadow) BOOL showBottomShadow;
  65. /**
  66. A Boolean value that controls whether the divider is visible between each segment. Default is `NO`.
  67. */
  68. @property (nonatomic, assign, getter=isShowsVerticalDivider) BOOL showsVerticalDivider;
  69. /**
  70. A Boolean value that controls whether the indicator is visible. Default is `YES`.
  71. */
  72. @property (nonatomic, assign, getter=isShowsIndicator) BOOL showsIndicator;
  73. /**
  74. The width style of indicator. Default is full.
  75. */
  76. @property (nonatomic, assign) WNSegmentedControlIndicatorWidthStyle indicatorWidthStyle;
  77. /**
  78. * Default is YES. Set to NO to disable animation during user selection.
  79. */
  80. @property (nonatomic) BOOL indicatorAnimate;
  81. /**
  82. * Default is NO. Set to NO to disable animation during user selection.
  83. */
  84. @property (nonatomic) BOOL textAnimate;
  85. /**
  86. The height of the indicator. The default is 2.0.
  87. */
  88. @property (nonatomic, assign) CGFloat indicatorHeight;
  89. /**
  90. The background color of the `YCSegmentedControl`. The default is yche blue.
  91. */
  92. @property (nonatomic, strong) UIColor *indicatorBackgroundColor;
  93. /**
  94. The location of indicator. Could be top or bottom. Default is bottom.
  95. */
  96. @property (nonatomic, assign) WNSegmentedControlIndicatorLocate indicatorLocate;
  97. /**
  98. 滑动时显示左右两侧渐变效果
  99. */
  100. @property (nonatomic, assign, getter=isShowGradient) BOOL showGradient;
  101. @end
  102. NS_ASSUME_NONNULL_END