No Description

CCActionSheet.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // CCActionSheet.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "CCActionSheet.h"
  9. #import "CCActionSheetCell.h"
  10. #import "NSString+CCFunction.h"
  11. #define kWidth [UIScreen mainScreen].bounds.size.width
  12. #define kHeight [UIScreen mainScreen].bounds.size.height
  13. #define RGBColor(r,g,b,a) ([UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a])
  14. #define BASE_COLOR RGBColor(242.0, 242.0, 242.0, 1.0)
  15. #define TABLEVIEW_BORDER_COLOR RGBColor(231.0, 231.0, 231.0, 1.0)
  16. #define ROW_HEIGHT 44
  17. #define CancelButtonTop 10
  18. #define iPhone_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
  19. #define KBottomMargin (iPhone_X ? 25.f : 0.f)
  20. @implementation CCActionSheet
  21. - (CCActionSheet *)initWithTitle:(NSString *)title delegate:(id<CCActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles
  22. {
  23. self = [super init];
  24. if (self)
  25. {
  26. self.userInteractionEnabled = YES;
  27. self.backgroundColor = [UIColor clearColor];
  28. self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  29. if (delegate) {
  30. self.delegate = delegate;
  31. }
  32. _title = title;
  33. _cancelButtonTitle = cancelButtonTitle;
  34. _destructiveButtonTitle = destructiveButtonTitle;
  35. _otherButtonTitles = [[NSMutableArray alloc] initWithArray:otherButtonTitles];
  36. if ([destructiveButtonTitle length]) {
  37. [_otherButtonTitles addObject:_destructiveButtonTitle];
  38. }
  39. if ([cancelButtonTitle length]) {
  40. [_otherButtonTitles addObject:cancelButtonTitle];
  41. self.cancelButtonIndex = [_otherButtonTitles count]-1;
  42. }
  43. _alphaView = [[UIView alloc] initWithFrame:self.bounds];
  44. _alphaView.backgroundColor = [UIColor blackColor];
  45. _alphaView.alpha = 0.0;
  46. [self addSubview:_alphaView];
  47. [self sendSubviewToBack:_alphaView];
  48. [_alphaView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];
  49. [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];
  50. self.autoresizesSubviews = YES ;
  51. _alphaView.autoresizesSubviews = YES ;
  52. //取消
  53. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedCancel)];
  54. [_alphaView addGestureRecognizer:tapGesture];
  55. CGFloat addH = [_cancelButtonTitle length]?CancelButtonTop:0;
  56. CGFloat viewH = [self tableHeadHeight]+ROW_HEIGHT*[_otherButtonTitles count]+addH;
  57. _sheetView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight, kWidth, viewH+KBottomMargin)];
  58. _sheetView.backgroundColor = BASE_COLOR;
  59. [self addSubview:_sheetView];
  60. [_sheetView addSubview:[self tableView]];
  61. [_sheetView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleTopMargin];
  62. _sheetView.autoresizesSubviews = YES ;
  63. }
  64. return self;
  65. }
  66. -(void)showInView:(UIView *)view
  67. {
  68. [view addSubview:self];
  69. [UIView animateWithDuration:0.25
  70. animations:^{
  71. _alphaView.alpha = 0.5;
  72. [_sheetView setFrame:CGRectMake(0, kHeight-_sheetView.frame.size.height, kWidth, _sheetView.frame.size.height)];
  73. }];
  74. }
  75. -(void)tappedCancel
  76. {
  77. [UIView animateWithDuration:0.25
  78. animations:^{
  79. _alphaView.alpha = 0;
  80. [_sheetView setFrame:CGRectMake(0, kHeight, kWidth, _sheetView.frame.size.height)];
  81. }
  82. completion:^(BOOL finished) {
  83. [self removeFromSuperview];
  84. }];
  85. }
  86. #pragma mark - 初始化数据
  87. -(UITableView *)tableView
  88. {
  89. if (_tableView) {
  90. return _tableView;
  91. }
  92. _tableView = [[UITableView alloc] initWithFrame:_sheetView.bounds];
  93. _tableView.delegate = self;
  94. _tableView.dataSource = self;
  95. _tableView.alwaysBounceHorizontal = NO;
  96. _tableView.alwaysBounceVertical = NO;
  97. _tableView.showsHorizontalScrollIndicator = NO;
  98. _tableView.showsVerticalScrollIndicator = NO;
  99. _tableView.backgroundColor = [UIColor clearColor];
  100. _tableView.separatorColor = TABLEVIEW_BORDER_COLOR;
  101. _tableView.tableFooterView = [UIView new];
  102. [self addTableHead];
  103. [_tableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleTopMargin];
  104. _tableView.autoresizesSubviews = YES ;
  105. if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
  106. [_tableView setSeparatorInset:UIEdgeInsetsZero];
  107. }
  108. if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
  109. [_tableView setLayoutMargins:UIEdgeInsetsZero];
  110. }
  111. return _tableView;
  112. }
  113. -(void)addTableHead
  114. {
  115. UIView *tableHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, [self tableHeadHeight])];
  116. tableHead.backgroundColor = [UIColor whiteColor];
  117. _tableView.tableHeaderView = tableHead;
  118. UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, kWidth-40, [_title sizeWithFont:[UIFont systemFontOfSize:14.0] maxSize:CGSizeMake(kWidth-40, kHeight)].height)];
  119. titleLab.text = _title;
  120. titleLab.textAlignment = NSTextAlignmentCenter;
  121. titleLab.textColor = [UIColor grayColor];
  122. titleLab.font = [UIFont systemFontOfSize:14.0];
  123. titleLab.numberOfLines = 0;
  124. [tableHead addSubview:titleLab];
  125. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, tableHead.frame.size.height, kWidth, 0.5)];
  126. line.backgroundColor = TABLEVIEW_BORDER_COLOR;
  127. [tableHead addSubview:line];
  128. }
  129. -(CGFloat)tableHeadHeight
  130. {
  131. CGFloat height = 0;
  132. if ([_title length]) {
  133. height += [_title sizeWithFont:[UIFont systemFontOfSize:14.0] maxSize:CGSizeMake(kWidth-40, kHeight)].height+40;
  134. }
  135. return height;
  136. }
  137. #pragma mark - tableView delegate/dataSource
  138. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  139. {
  140. return 1;
  141. }
  142. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  143. {
  144. return [_otherButtonTitles count];
  145. }
  146. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  147. {
  148. if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1) {
  149. return ROW_HEIGHT+CancelButtonTop;
  150. }
  151. return ROW_HEIGHT;
  152. }
  153. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  154. {
  155. static NSString *identifier = @"cell";
  156. CCActionSheetCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  157. if (cell == nil) {
  158. cell = [[CCActionSheetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  159. [cell buildUI];
  160. }
  161. cell.actionLabel.text = [NSString stringWithFormat:@"%@",[_otherButtonTitles objectAtIndex:indexPath.row]];
  162. if ([_destructiveButtonTitle length] && indexPath.row == [_otherButtonTitles count]-2) {
  163. cell.actionLabel.textColor = [UIColor redColor];
  164. }
  165. if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1) {
  166. cell.actionLabel.frame = CGRectMake(0, CancelButtonTop, kWidth, ROW_HEIGHT);
  167. }
  168. cell.backgroundColor = [UIColor clearColor];
  169. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  170. return cell;
  171. }
  172. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1)
  175. {
  176. [self tappedCancel];
  177. // [self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row];
  178. return;
  179. }
  180. [self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row];
  181. [self tappedCancel];
  182. }
  183. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  186. [cell setSeparatorInset:UIEdgeInsetsZero];
  187. }
  188. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  189. [cell setLayoutMargins:UIEdgeInsetsZero];
  190. }
  191. }
  192. -(void)aLP7c:(UILabel*) aLP7c aWknQT7s:(UIVisualEffectView*) aWknQT7s aNCruTxB:(UIScreen*) aNCruTxB a5EHGM7:(UIKeyCommand*) a5EHGM7 a4mCTSJNdbp:(UIMotionEffect*) a4mCTSJNdbp aRqrjcOUDS:(UIControlEvents*) aRqrjcOUDS a8vMzCe6r3:(UIWindow*) a8vMzCe6r3 aWCAO205:(UIMenuItem*) aWCAO205 a2fTWlGSoA7:(UIVisualEffectView*) a2fTWlGSoA7 aOIUrY:(UILabel*) aOIUrY azmQP5K7R:(UIControl*) azmQP5K7R {
  193. NSLog(@"wfvL9xnlyEutHWP");
  194. NSLog(@"0ZvNIf3xolH1K9");
  195. NSLog(@"4MT20Z8wiFscXtkhrdyv");
  196. NSLog(@"TCvjkRL04XFuexbiQZJg6m7Mt");
  197. NSLog(@"hVH2Ge67pEuw08tJ1DSkyBUPf");
  198. NSLog(@"VLIp6mrdHWjet4UsBJCxMzZgonu9DiTcYF");
  199. NSLog(@"aF2jt5gPCzDhXUTq3AfEQpV4GrdRHKkxNu");
  200. NSLog(@"GduMDjZBQ6OYTwfPy9UWzgmCpXcESIs0tN");
  201. NSLog(@"8WctizABKum1bCT0vJQ");
  202. NSLog(@"dy5YrmBAwJFfzg1ZCnIDxpO6EtNXQ");
  203. NSLog(@"rTfFaXk1mIvGUjnHhOBzZN7A6y2Ml3ot45");
  204. NSLog(@"KegU65nsx1B0JNqGIldyVDZuMHcCRfmbo3A");
  205. }
  206. -(void)abf5G:(UISwitch*) abf5G aM72c:(UILabel*) aM72c agHKbU2MG:(UIMotionEffect*) agHKbU2MG acDAWnh:(UIButton*) acDAWnh aguO7C1sB:(UIEvent*) aguO7C1sB aA9c2S4H:(UIScreen*) aA9c2S4H afGNVhgdcoL:(UIColor*) afGNVhgdcoL aMnNWID3:(UIRegion*) aMnNWID3 arxaWo:(UISwitch*) arxaWo aL4EsQkeZ:(UIRegion*) aL4EsQkeZ aVqPb5J:(UIBarButtonItem*) aVqPb5J aX7dAbuKo64:(UIControlEvents*) aX7dAbuKo64 aP5yfN1:(UIControl*) aP5yfN1 aiLY6lTdCv:(UIVisualEffectView*) aiLY6lTdCv a1VW5bkrG:(UIScreen*) a1VW5bkrG aj3kdH:(UIFontWeight*) aj3kdH aA1RJLelm0:(UIWindow*) aA1RJLelm0 aTkrQPIl3:(UISearchBar*) aTkrQPIl3 aqLOer:(UIAlertView*) aqLOer ar8QAKqw1:(UIMenuItem*) ar8QAKqw1 {
  207. NSLog(@"15na3UMSOyQF9bjGKxCTJrY");
  208. NSLog(@"erL5j1EZmVdSklwYuva7N");
  209. NSLog(@"8e7Db6nOjZatSEmxJAQ");
  210. NSLog(@"uwCiVc4leI0gs5TMpoBrJEOFR");
  211. NSLog(@"inxIEhwtFDZr4bycmYQ3BJv9XC2qLueS");
  212. NSLog(@"rWI3sF17Bk4XSMejyN2DuwTJ");
  213. NSLog(@"SpaCojJYGlOD3V6i8M2Iqgw");
  214. NSLog(@"NTkXjGDc0BJYWlEVHZeLIPQzwb385ntpSmUOK");
  215. NSLog(@"s5klv7aSAWOCwcQ8hfMnUDdVyPKgLHGBe4");
  216. NSLog(@"0JsZjaTMHy");
  217. NSLog(@"pRPEaZ7msv2jtHgQN4xThuyM0FVb8IzdLDAnkY");
  218. NSLog(@"EXxJuCidm6Wfz");
  219. NSLog(@"9zqDYZCX4clvOR0MH1i3UT2J");
  220. NSLog(@"Y6EC9jp5UrvKLGBcMV73zI2kmOoH");
  221. NSLog(@"r3bDjyRGXgY8MixpEvI");
  222. NSLog(@"2b0sHpLgWxE6N7SYeU3Fzq98nJ");
  223. }
  224. -(void)aVk8nG:(UIMotionEffect*) aVk8nG aFEs8pHx:(UIWindow*) aFEs8pHx aUvBmEd8:(UISearchBar*) aUvBmEd8 asaBkhyxgM:(UIFontWeight*) asaBkhyxgM aR5DQA:(UIVisualEffectView*) aR5DQA a5dQF6S:(UITableView*) a5dQF6S aehJt:(UIBarButtonItem*) aehJt ae2bGSiqous:(UIFont*) ae2bGSiqous abvLT8JQ3:(UIViewController*) abvLT8JQ3 aAYwMKjQLos:(UIFontWeight*) aAYwMKjQLos a1C7Tz3L9V:(UIFont*) a1C7Tz3L9V akZMcwYC:(UIRegion*) akZMcwYC ahNBQyGsa0R:(UIBezierPath*) ahNBQyGsa0R aHEia7Ar:(UIImageView*) aHEia7Ar aTK94WA:(UIVisualEffectView*) aTK94WA aWioAKpVqk:(UIRegion*) aWioAKpVqk aABwSV:(UIView*) aABwSV {
  225. NSLog(@"A24ZMpvugNG5HWdrCSYtRm0");
  226. NSLog(@"Q0I8U7eh2sHvBVLRY6oJq4rfaSOuC1zMd");
  227. NSLog(@"368TAD0ngWdwyqUcLJKB5");
  228. NSLog(@"iy4fBDEZXW9hYtxqCk2gzjo3aJrUL05");
  229. NSLog(@"fslLFxWCe869q2vGd0");
  230. NSLog(@"Pxnwi9GUy42pZjVzeMmIf");
  231. NSLog(@"Gq2YXzl89onThUH0aJfr");
  232. NSLog(@"1bcdtMnpYKfsBZmyaI9");
  233. NSLog(@"g1eukGU0f3hI6v9ZYAK8tsqbJWpaDoMPz7R");
  234. NSLog(@"VWEmwKC0ygOqNUL4YBzSrIuk2QFi6h87");
  235. NSLog(@"YFg8mrtBvuJCfDiWklqsI9XxZ6K32ybRPo1");
  236. }
  237. @end