HMSegmentedControl.h
7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// BBAHMSegmentedControl.h
// BBAHMSegmentedControl
//
// Created by Hesham Abd-Elmegid on 23/12/12.
// Copyright (c) 2012-2015 Hesham Abd-Elmegid. All rights reserved.
//
/******************************************************************************/
// 描述:Sprint7.0引入 github:https://github.com/HeshamMegid/HMSegmentedControl
/******************************************************************************/
#import <UIKit/UIKit.h>
@class BBAHMSegmentedControl;
typedef void (^IndexChangeBlock)(NSInteger index);
typedef NSAttributedString *(^BBAHMTitleFormatterBlock)(BBAHMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected);
typedef enum {
BBAHMSegmentedControlSelectionStyleTextWidthStripe, // Indicator width will only be as big as the text width
BBAHMSegmentedControlSelectionStyleFullWidthStripe, // Indicator width will fill the whole segment
BBAHMSegmentedControlSelectionStyleBox, // A rectangle that covers the whole segment
BBAHMSegmentedControlSelectionStyleArrow // An arrow in the middle of the segment pointing up or down depending on `BBAHMSegmentedControlSelectionIndicatorLocation`
} BBAHMSegmentedControlSelectionStyle;
typedef enum {
BBAHMSegmentedControlSelectionIndicatorLocationUp,
BBAHMSegmentedControlSelectionIndicatorLocationDown,
BBAHMSegmentedControlSelectionIndicatorLocationNone // No selection indicator
} BBAHMSegmentedControlSelectionIndicatorLocation;
typedef enum {
BBAHMSegmentedControlSegmentWidthStyleFixed, // Segment width is fixed
BBAHMSegmentedControlSegmentWidthStyleDynamic, // Segment width will only be as big as the text width (including inset)
} BBAHMSegmentedControlSegmentWidthStyle;
typedef NS_OPTIONS(NSInteger, BBAHMSegmentedControlBorderType) {
BBAHMSegmentedControlBorderTypeNone = 0,
BBAHMSegmentedControlBorderTypeTop = (1 << 0),
BBAHMSegmentedControlBorderTypeLeft = (1 << 1),
BBAHMSegmentedControlBorderTypeBottom = (1 << 2),
BBAHMSegmentedControlBorderTypeRight = (1 << 3)
};
enum {
BBAHMSegmentedControlNoSegment = -1 // Segment index for no selected segment
};
typedef enum {
BBAHMSegmentedControlTypeText,
BBAHMSegmentedControlTypeImages,
BBAHMSegmentedControlTypeTextImages
} BBAHMSegmentedControlType;
__attribute__((deprecated("请使用BBAMultiTabBar")))
@interface BBAHMSegmentedControl : UIControl
@property (nonatomic, strong) NSArray *sectionTitles;
@property (nonatomic, strong) NSArray *sectionImages;
@property (nonatomic, strong) NSArray *sectionSelectedImages;
/**
Provide a block to be executed when selected index is changed.
Alternativly, you could use `addTarget:action:forControlEvents:`
*/
@property (nonatomic, copy) IndexChangeBlock indexChangeBlock;
/**
Used to apply custom text styling to titles when set.
When this block is set, no additional styling is applied to the `NSAttributedString` object returned from this block.
*/
@property (nonatomic, copy) BBAHMTitleFormatterBlock titleFormatter;
/**
Text attributes to apply to item title text.
*/
@property (nonatomic, strong) NSDictionary *titleTextAttributes UI_APPEARANCE_SELECTOR;
/*
Text attributes to apply to selected item title text.
Attributes not set in this dictionary are inherited from `titleTextAttributes`.
*/
@property (nonatomic, strong) NSDictionary *selectedTitleTextAttributes UI_APPEARANCE_SELECTOR;
/**
Segmented control background color.
Default is `[UIColor whiteColor]`
*/
@property (nonatomic, strong) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
/**
Color for the selection indicator stripe/box
Default is `R:52, G:181, B:229`
*/
@property (nonatomic, strong) UIColor *selectionIndicatorColor UI_APPEARANCE_SELECTOR;
/**
Color for the vertical divider between segments.
Default is `[UIColor blackColor]`
*/
@property (nonatomic, strong) UIColor *verticalDividerColor UI_APPEARANCE_SELECTOR;
/**
Opacity for the seletion indicator box.
Default is `0.2f`
*/
@property (nonatomic) CGFloat selectionIndicatorBoxOpacity;
/**
Width the vertical divider between segments that is added when `verticalDividerEnabled` is set to YES.
Default is `1.0f`
*/
@property (nonatomic, assign) CGFloat verticalDividerWidth;
/**
Specifies the style of the control
Default is `BBAHMSegmentedControlTypeText`
*/
@property (nonatomic, assign) BBAHMSegmentedControlType type;
/**
Specifies the style of the selection indicator.
Default is `BBAHMSegmentedControlSelectionStyleTextWidthStripe`
*/
@property (nonatomic, assign) BBAHMSegmentedControlSelectionStyle selectionStyle;
/**
Specifies the style of the segment's width.
Default is `BBAHMSegmentedControlSegmentWidthStyleFixed`
*/
@property (nonatomic, assign) BBAHMSegmentedControlSegmentWidthStyle segmentWidthStyle;
/**
Specifies the location of the selection indicator.
Default is `BBAHMSegmentedControlSelectionIndicatorLocationUp`
*/
@property (nonatomic, assign) BBAHMSegmentedControlSelectionIndicatorLocation selectionIndicatorLocation;
/*
Specifies the border type.
Default is `BBAHMSegmentedControlBorderTypeNone`
*/
@property (nonatomic, assign) BBAHMSegmentedControlBorderType borderType;
/**
Specifies the border color.
Default is `[UIColor blackColor]`
*/
@property (nonatomic, strong) UIColor *borderColor;
/**
Specifies the border width.
Default is `1.0f`
*/
@property (nonatomic, assign) CGFloat borderWidth;
/**
Default is YES. Set to NO to deny scrolling by dragging the scrollView by the user.
*/
@property(nonatomic, getter = isUserDraggable) BOOL userDraggable;
/**
Default is YES. Set to NO to deny any touch events by the user.
*/
@property(nonatomic, getter = isTouchEnabled) BOOL touchEnabled;
/**
Default is NO. Set to YES to show a vertical divider between the segments.
*/
@property(nonatomic, getter = isVerticalDividerEnabled) BOOL verticalDividerEnabled;
/**
Index of the currently selected segment.
*/
@property (nonatomic, assign) NSInteger selectedSegmentIndex;
/**
Height of the selection indicator. Only effective when `BBAHMSegmentedControlSelectionStyle` is either `BBAHMSegmentedControlSelectionStyleTextWidthStripe` or `BBAHMSegmentedControlSelectionStyleFullWidthStripe`.
Default is 5.0
*/
@property (nonatomic, readwrite) CGFloat selectionIndicatorHeight;
/**
Edge insets for the selection indicator.
NOTE: This does not affect the bounding box of BBAHMSegmentedControlSelectionStyleBox
When BBAHMSegmentedControlSelectionIndicatorLocationUp is selected, bottom edge insets are not used
When BBAHMSegmentedControlSelectionIndicatorLocationDown is selected, top edge insets are not used
Defaults are top: 0.0f
left: 0.0f
bottom: 0.0f
right: 0.0f
*/
@property (nonatomic, readwrite) UIEdgeInsets selectionIndicatorEdgeInsets;
/**
Inset left and right edges of segments.
Default is UIEdgeInsetsMake(0, 5, 0, 5)
*/
@property (nonatomic, readwrite) UIEdgeInsets segmentEdgeInset;
/**
Default is YES. Set to NO to disable animation during user selection.
*/
@property (nonatomic) BOOL shouldAnimateUserSelection;
- (id)initWithSectionTitles:(NSArray *)sectiontitles;
- (id)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages;
- (instancetype)initWithSectionImages:(NSArray *)sectionImages sectionSelectedImages:(NSArray *)sectionSelectedImages titlesForSections:(NSArray *)sectiontitles;
- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated;
- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated notify:(BOOL)notify;
- (void)setIndexChangeBlock:(IndexChangeBlock)indexChangeBlock;
- (void)setTitleFormatter:(BBAHMTitleFormatterBlock)titleFormatter;
- (void)updateBadgeNumber:(NSUInteger)badge atIndex:(NSUInteger)index;//add by guojin 20151124,sprint7.0
//10.13 增加segment文字带有小红点,注意此处的飘新逻辑:为了数字飘新和红点飘新共存,
//所以当badge>0则是数字飘新,badge=0时则小红点飘新,badge=-1才是清除飘新,使用方要注意
@property (nonatomic, strong) NSMutableArray *badgeArray;
@end