BBAActionSheet.h
15.9 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
//
// BBAActionSheet.h
// SWAN
//
// Created by baidu on 2015/4/27.
//
// Copyright © 2018年 Baidu. All rights reserved.
//
#import <UIKit/UIKit.h>
@class BBAActionSheet;
NS_ASSUME_NONNULL_BEGIN
#define BBASM_BUTTON_CONTENT_Key @"content"
#define BBASM_BUTTON_HEIGHT_Key @"height"
#pragma mark - BBAActionSheet Block
/**
Handle click button.
*/
typedef void(^BBAActionSheetClickedHandler)(BBAActionSheet *actionSheet, NSInteger buttonIndex);
/**
Handle action sheet will present.
*/
typedef void(^BBAActionSheetWillPresentHandler)(BBAActionSheet *actionSheet);
/**
Handle action sheet did present.
*/
typedef void(^BBAActionSheetDidPresentHandler)(BBAActionSheet *actionSheet);
/**
Handle action sheet will dismiss.
*/
typedef void(^BBAActionSheetWillDismissHandler)(BBAActionSheet *actionSheet, NSInteger buttonIndex);
/**
Handle action sheet did dismiss.
*/
typedef void(^BBAActionSheetDidDismissHandler)(BBAActionSheet *actionSheet, NSInteger buttonIndex);
#pragma mark - BBAActionSheet Delegate
@protocol BBAActionSheetDelegate <NSObject>
@optional
/**
Handle click button.
*/
- (void)actionSheet:(BBAActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
/**
Handle action sheet will present.
*/
- (void)willPresentActionSheet:(BBAActionSheet *)actionSheet;
/**
Handle action sheet did present.
*/
- (void)didPresentActionSheet:(BBAActionSheet *)actionSheet;
/**
Handle action sheet will dismiss.
*/
- (void)actionSheet:(BBAActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
/**
Handle action sheet did dismiss.
*/
- (void)actionSheet:(BBAActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
@end
#pragma mark - BBAActionSheet
@interface BBAActionSheet : UIView
#pragma mark - Properties
/**
Title.
*/
@property (nullable, nonatomic, copy) NSString *title;
/**
Cancel button's title.
*/
@property (nullable, nonatomic, copy) NSString *cancelButtonTitle;
/**
Cancel button's index.
*/
@property (nonatomic, assign, readonly) NSInteger cancelButtonIndex;
/**
BBAActionSheet's delegate.
*/
@property (nullable, nonatomic, weak) id<BBAActionSheetDelegate> delegate;
/**
Deprecated, use `destructiveButtonIndexSet` instead.
*/
@property (nullable, nonatomic, strong) NSIndexSet *redButtonIndexSet __deprecated_msg("Property deprecated. Use `destructiveButtonIndexSet` instead.");
/**
All destructive buttons' set. You should give it the `NSNumber` type items.
*/
@property (nullable, nonatomic, strong) NSIndexSet *destructiveButtonIndexSet;
/**
Destructive button's color. Default is RGB(254, 67, 37).
*/
@property (nonatomic, strong) UIColor *destructiveButtonColor;
/**
Destructive button's background color. Default is `[UIColor clearColor]`.
*/
@property (nonatomic, strong) UIColor *destructiveButtonBgColor;
/**
Title's color. Default is `[UIColor blackColor]`.
*/
@property (nonatomic, strong) UIColor *titleColor;
/**
Cancel button's color. Default is `buttonColor`.
*/
@property (nonatomic, strong) UIColor *cancelButtonColor;
/**
Cancel button's backgroundColor, without destructive buttons. Default is `[UIColor clarColor]`.
*/
@property (nonatomic, strong) UIColor *cancelButtonBgColor;
/**
Buttons' color, without destructive buttons. Default is `[UIColor blackColor]`.
*/
@property (nonatomic, strong) UIColor *buttonColor;
/**
Buttons' backgroundColor, without destructive buttons. Default is `[UIColor clarColor]`.
*/
@property (nonatomic, strong) UIColor *buttonBgColor;
/**
Title's font. Default is `[UIFont systemFontOfSize:14.0f]`.
*/
@property (nonatomic, strong) UIFont *titleFont;
/**
All buttons' font. Default is `[UIFont systemFontOfSize:18.0f]`.
*/
@property (nonatomic, strong) UIFont *buttonFont;
/**
All buttons' height. Default is 49.0f;
*/
@property (nonatomic, assign) CGFloat buttonHeight;
/**
All buttons' corner. Default is 0.0f;
*/
@property (nonatomic, assign) CGFloat buttonCornerRadius;
/**
If buttons' bottom view can scrolling. Default is NO.
*/
@property (nonatomic, assign, getter=canScrolling) BOOL scrolling;
/**
Visible buttons' count. You have to set `scrolling = YES` if you want to set it.
*/
@property (nonatomic, assign) CGFloat visibleButtonCount;
/**
Animation duration. Default is 0.3 seconds.
*/
@property (nonatomic, assign) CGFloat animationDuration;
/**
Dismiss animation duration. Default is 0.16 seconds.
*/
@property (nonatomic, assign) CGFloat dismissAnimationDuration;
/**
Opacity of dark background. Default is 0.3f.
*/
@property (nonatomic, assign) CGFloat darkOpacity;
/**
If you can tap darkView to dismiss. Defalut is NO, you can tap dardView to dismiss.
*/
@property (nonatomic, assign) BOOL darkViewNoTaped;
/**
Title's edge insets. Default is `UIEdgeInsetsMake(15.0f, 15.0f, 15.0f, 15.0f)`.
*/
@property (nonatomic, assign) UIEdgeInsets titleEdgeInsets;
/**
Button's edge insets. Default is `UIEdgeInsetsMake(8.0, 15.0, 8.0f, 15.0f)`.
*/
@property (nonatomic, assign) UIEdgeInsets buttonEdgeInsets;
///**
// ActionSheet's edge insets. Default is `UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)`.
// */
//@property (nonatomic, assign) UIEdgeInsets actionSheetEdgeInsets;
/**
Cell's separator color. Default is `RGBA(170/255.0f, 170/255.0f, 170/255.0f, 0.5f)`.
*/
@property (nonatomic, strong) UIColor *separatorColor;
/**
Title can be limit in numberOfTitleLines. Default is 0.
*/
@property (nonatomic, assign) NSInteger numberOfTitleLines;
/**
Auto hide when the device rotated. Default is NO, won't auto hide.
*/
@property (nonatomic, assign) BOOL autoHideWhenDeviceRotated;
/**
BBAActionSheet clicked handler.
*/
@property (nullable, nonatomic, copy) BBAActionSheetClickedHandler clickedHandler;
/**
BBAActionSheet will present handler.
*/
@property (nullable, nonatomic, copy) BBAActionSheetWillPresentHandler willPresentHandler;
/**
BBAActionSheet did present handler.
*/
@property (nullable, nonatomic, copy) BBAActionSheetDidPresentHandler didPresentHandler;
/**
BBAActionSheet will dismiss handler.
*/
@property (nullable, nonatomic, copy) BBAActionSheetWillDismissHandler willDismissHandler;
/**
BBAActionSheet did dismiss handler.
*/
@property (nullable, nonatomic, copy) BBAActionSheetDidDismissHandler didDismissHandler;
#pragma mark - Methods
- (NSAttributedString *)getOtherButtonContentAtIndex:(NSUInteger)index;
- (float)getOtherButtonHeightAtIndex:(NSUInteger)index;
#pragma mark Delegate
/**
Initialize an instance of BBAActionSheet (Delegate).
@param title title
@param delegate delegate
@param cancelButtonTitle cancelButtonTitle
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
delegate:(nullable id<BBAActionSheetDelegate>)delegate
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Delegate).
@param title title
@param delegate delegate
@param cancelButtonTitle cancelButtonTitle
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
delegate:(nullable id<BBAActionSheetDelegate>)delegate
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
/**
Initialize an instance of BBAActionSheet (Delegate).
@param title title
@param delegate delegate
@param cancelButtonTitle cancelButtonTitle
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
delegate:(nullable id<BBAActionSheetDelegate>)delegate
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Delegate).
@param title title
@param delegate delegate
@param cancelButtonTitle cancelButtonTitle
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
delegate:(nullable id<BBAActionSheetDelegate>)delegate
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
#pragma mark Block
/**
Initialize an instance of BBAActionSheet (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param clickedHandler clickedHandler
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
clicked:(nullable BBAActionSheetClickedHandler)clickedHandler
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param clickedHandler clickedHandler
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
clicked:(nullable BBAActionSheetClickedHandler)clickedHandler
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
/**
Initialize an instance of BBAActionSheet (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param clickedHandler clickedHandler
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
clicked:(nullable BBAActionSheetClickedHandler)clickedHandler
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param clickedHandler clickedHandler
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
clicked:(nullable BBAActionSheetClickedHandler)clickedHandler
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
/**
Initialize an instance of BBAActionSheet (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param didDismissHandler didDismissHandler
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
didDismiss:(nullable BBAActionSheetDidDismissHandler)didDismissHandler
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param didDismissHandler didDismissHandler
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
+ (instancetype)sheetWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
didDismiss:(nullable BBAActionSheetDidDismissHandler)didDismissHandler
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
/**
Initialize an instance of BBAActionSheet (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param didDismissHandler didDismissHandler
@param otherButtonTitles otherButtonTitles
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
didDismiss:(nullable BBAActionSheetDidDismissHandler)didDismissHandler
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Initialize an instance of BBAActionSheet with title array (Block).
@param title title
@param cancelButtonTitle cancelButtonTitle
@param didDismissHandler didDismissHandler
@param otherButtonTitleArray otherButtonTitleArray
@return An instance of BBAActionSheet.
*/
- (instancetype)initWithTitle:(nullable NSString *)title
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
didDismiss:(nullable BBAActionSheetDidDismissHandler)didDismissHandler
otherButtonTitleArray:(nullable NSArray<NSDictionary *> *)otherButtonTitleArray;
#pragma mark Append & Show
/**
Append buttons with titles.
@param titles titles
*/
- (void)appendButtonsWithTitles:(nullable NSString *)titles, ... NS_REQUIRES_NIL_TERMINATION;
/**
Append button at index with title.
@param title title
@param index index
*/
- (void)appendButtonWithTitle:(nullable NSString *)title atIndex:(NSInteger)index;
/**
Append buttons at indexSet with titles.
@param titles titles
@param indexes indexes
*/
- (void)appendButtonsWithTitles:(NSArray<NSString *> *)titles atIndexes:(NSIndexSet *)indexes;
/**
Append button at index with title.
@param content 按钮展示内容
@param height 按钮高度
@param index 按钮显示位置
*/
- (void)appendButtonWithTitle:(NSAttributedString *)content
height:(NSNumber *)height
atIndex:(NSInteger)index;
/**
Show the instance of BBAActionSheet.
*/
- (void)show;
/**
Get button title with index
@param index index
@return button title
*/
- (NSString *)buttonTitleAtIndex:(NSInteger)index;
#pragma mark added by zhangjian
////////////////////////////////////////////////////////////////////////////////////////////////////////////
@property (nonatomic, strong) NSArray<NSDictionary *> *otherButtonTitles;
/// 粗的分割线颜色
@property (nonatomic, assign, getter=spliteViewOrCellWidth) CGFloat splitLineWidth;
/// cell高亮颜色
@property (nonatomic, strong) UIColor *cellsHightlightedColor;
/// 取消按钮高亮颜色
@property (nonatomic, strong) UIColor *cancelButtonHightlightedColor;
/// 取消按钮正常颜色
@property (nonatomic, strong) UIColor *cancelButtonNormalBgColor;
/// 粗的分割线
@property (nonatomic, strong) UIColor *thickSeparatorColor;
/// 标题背景颜色
@property (nonatomic, nullable, strong) UIColor *titleBgColor;
/**
* @brief 面部分总体高度,如果上面是可滑动的,那么就是压缩后的了, 包括标题高度
* @return CGFloat类型的数字
*/
-(CGFloat)otherButtonsTotalHeight;
/**
* @brief tableView整体高度, 如果tableView可以滚动,那么就是可视区的高度
* @return CGFloat类型的数字
*/
-(CGFloat)tableViewHeight;
/**
* @brief 子类可以继承,用于实现自定义效果的cell等
* @return TableViewCell
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
/**
* @brief 子类可以继承,用于自定义tableView高度
* @return cell高度
*/
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
/**
* dismiss actionView
*/
- (void)dismissActionView;
@end
NS_ASSUME_NONNULL_END