| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // WNSegmentControl.h
- #import <UIKit/UIKit.h>
- /// 指示器位置
- typedef NS_ENUM(NSUInteger, WNSegmentedControlIndicatorLocate) {
- WNSegmentedControlIndicatorLocateTop,
- WNSegmentedControlIndicatorLocateBottom,
- };
- /// 指示器宽度风格
- typedef NS_ENUM(NSUInteger, WNSegmentedControlIndicatorWidthStyle) {
- WNSegmentedControlIndicatorWidthStyleFull,
- WNSegmentedControlIndicatorWidthStyleText,
- WNSegmentedControlIndicatorWidthStyleShort,
- };
- typedef NS_ENUM(NSInteger, WNSegmentedControlWidthStyle) {
- WNSegmentedControlWidthStyleFixed, // 平均分割
- WNSegmentedControlWidthStyleDynamic, // 同字体宽度
- };
- NS_ASSUME_NONNULL_BEGIN
- @interface WNSegmentControl :UIControl
- ///---------------------
- /// @name Initialization
- ///---------------------
- - (instancetype)initWithTitles:(NSArray <NSString *> *)titles;
- - (instancetype)initWithImages:(NSArray <UIImage *> *)images;
- - (instancetype)initWithImages:(NSArray <UIImage *> *)images
- selectedImages:(nullable NSArray <UIImage *> *)selectedImages;
- - (instancetype)initWithAttributedTitles:(NSArray <NSAttributedString *> *)titles;
- - (nullable NSString *)titleAtIndex:(NSUInteger)index;
- - (nullable UIImage *)imageAtIndex:(NSUInteger)index;
- - (void)setTitle:(NSString *)title atIndex:(NSUInteger)index;
- - (void)setImage:(UIImage *)image atIndex:(NSUInteger)index;
- - (void)setImage:(UIImage *)image selectedImage:(nullable UIImage *)selectedImage atIndex:(NSUInteger)index;
- - (void)insertTitle:(NSString *)title atIndex:(NSUInteger)index;
- - (void)removeTitleAtIndex:(NSUInteger)index;
- - (void)setTitles:(NSArray<NSString *> *)titles;
- - (void)setTextAttributes:(nullable NSDictionary *)attributes forState:(UIControlState)state;
- - (void)setSelectedSegmentIndex:(NSUInteger)selectedSegmentIndex ignoreAction:(BOOL)ignoreAction;
- - (void)addTipViewWithGenerator:(UIView *(^)(NSUInteger index))viewGenerator;
- - (void)reloadData;
- @property (nonatomic, assign, readonly) NSUInteger numberOfSegments;
- @property (nonatomic, assign) NSUInteger selectedSegmentIndex;
- @property (nonatomic, assign) WNSegmentedControlWidthStyle widthStyle;
- @property (nonatomic, readwrite) UIEdgeInsets segmentEdgeInset;
- /**
- 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.
- */
- @property (nonatomic, assign) CGFloat horizontalPadding;
- /**
- A Boolean value that controls whether the top separator is visible. Default is `NO`.
- */
- @property (nonatomic, assign, getter=isShowsTopSeparator) BOOL showsTopSeparator;
- /**
- A Boolean value that controls whether the item separator is visible. Default is `NO`.
- */
- @property (nonatomic, assign, getter=isShowsItemSeparator) BOOL showsItemSeparator;
- /**
- A Boolean value that controls whether the bottom separator is visible. Default is `NO`.
- */
- @property (nonatomic, assign, getter=isShowsBottomSeparator) BOOL showsBottomSeparator;
- /**
- A Boolean value that controls whether the bottom shadow is visible. Default is `NO`.
- */
- @property (nonatomic, assign, getter=isShowBottomShadow) BOOL showBottomShadow;
- /**
- A Boolean value that controls whether the divider is visible between each segment. Default is `NO`.
- */
- @property (nonatomic, assign, getter=isShowsVerticalDivider) BOOL showsVerticalDivider;
- /**
- A Boolean value that controls whether the indicator is visible. Default is `YES`.
- */
- @property (nonatomic, assign, getter=isShowsIndicator) BOOL showsIndicator;
- /**
- The width style of indicator. Default is full.
- */
- @property (nonatomic, assign) WNSegmentedControlIndicatorWidthStyle indicatorWidthStyle;
- /**
- * Default is YES. Set to NO to disable animation during user selection.
- */
- @property (nonatomic) BOOL indicatorAnimate;
- /**
- * Default is NO. Set to NO to disable animation during user selection.
- */
- @property (nonatomic) BOOL textAnimate;
- /**
- The height of the indicator. The default is 2.0.
- */
- @property (nonatomic, assign) CGFloat indicatorHeight;
- /**
- The background color of the `YCSegmentedControl`. The default is yche blue.
- */
- @property (nonatomic, strong) UIColor *indicatorBackgroundColor;
- /**
- The location of indicator. Could be top or bottom. Default is bottom.
- */
- @property (nonatomic, assign) WNSegmentedControlIndicatorLocate indicatorLocate;
- /**
- 滑动时显示左右两侧渐变效果
- */
- @property (nonatomic, assign, getter=isShowGradient) BOOL showGradient;
- @end
- NS_ASSUME_NONNULL_END
|