// // CCActionSheet.m // YouHuiProject // // Created by 小花 on 2018/1/25. // Copyright © 2018年 kuxuan. All rights reserved. // #import "CCActionSheet.h" #import "CCActionSheetCell.h" #import "NSString+CCFunction.h" #define kWidth [UIScreen mainScreen].bounds.size.width #define kHeight [UIScreen mainScreen].bounds.size.height #define RGBColor(r,g,b,a) ([UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]) #define BASE_COLOR RGBColor(242.0, 242.0, 242.0, 1.0) #define TABLEVIEW_BORDER_COLOR RGBColor(231.0, 231.0, 231.0, 1.0) #define ROW_HEIGHT 44 #define CancelButtonTop 10 #define iPhone_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) #define KBottomMargin (iPhone_X ? 25.f : 0.f) @implementation CCActionSheet - (CCActionSheet *)initWithTitle:(NSString *)title delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles { self = [super init]; if (self) { self.userInteractionEnabled = YES; self.backgroundColor = [UIColor clearColor]; self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); if (delegate) { self.delegate = delegate; } _title = title; _cancelButtonTitle = cancelButtonTitle; _destructiveButtonTitle = destructiveButtonTitle; _otherButtonTitles = [[NSMutableArray alloc] initWithArray:otherButtonTitles]; if ([destructiveButtonTitle length]) { [_otherButtonTitles addObject:_destructiveButtonTitle]; } if ([cancelButtonTitle length]) { [_otherButtonTitles addObject:cancelButtonTitle]; self.cancelButtonIndex = [_otherButtonTitles count]-1; } _alphaView = [[UIView alloc] initWithFrame:self.bounds]; _alphaView.backgroundColor = [UIColor blackColor]; _alphaView.alpha = 0.0; [self addSubview:_alphaView]; [self sendSubviewToBack:_alphaView]; [_alphaView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight]; [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight]; self.autoresizesSubviews = YES ; _alphaView.autoresizesSubviews = YES ; //取消 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedCancel)]; [_alphaView addGestureRecognizer:tapGesture]; CGFloat addH = [_cancelButtonTitle length]?CancelButtonTop:0; CGFloat viewH = [self tableHeadHeight]+ROW_HEIGHT*[_otherButtonTitles count]+addH; _sheetView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight, kWidth, viewH+KBottomMargin)]; _sheetView.backgroundColor = BASE_COLOR; [self addSubview:_sheetView]; [_sheetView addSubview:[self tableView]]; [_sheetView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleTopMargin]; _sheetView.autoresizesSubviews = YES ; } return self; } -(void)showInView:(UIView *)view { [view addSubview:self]; [UIView animateWithDuration:0.25 animations:^{ _alphaView.alpha = 0.5; [_sheetView setFrame:CGRectMake(0, kHeight-_sheetView.frame.size.height, kWidth, _sheetView.frame.size.height)]; }]; } -(void)tappedCancel { [UIView animateWithDuration:0.25 animations:^{ _alphaView.alpha = 0; [_sheetView setFrame:CGRectMake(0, kHeight, kWidth, _sheetView.frame.size.height)]; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } #pragma mark - 初始化数据 -(UITableView *)tableView { if (_tableView) { return _tableView; } _tableView = [[UITableView alloc] initWithFrame:_sheetView.bounds]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.alwaysBounceHorizontal = NO; _tableView.alwaysBounceVertical = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.showsVerticalScrollIndicator = NO; _tableView.backgroundColor = [UIColor clearColor]; _tableView.separatorColor = TABLEVIEW_BORDER_COLOR; _tableView.tableFooterView = [UIView new]; [self addTableHead]; [_tableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleTopMargin]; _tableView.autoresizesSubviews = YES ; if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) { [_tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) { [_tableView setLayoutMargins:UIEdgeInsetsZero]; } return _tableView; } -(void)addTableHead { UIView *tableHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, [self tableHeadHeight])]; tableHead.backgroundColor = [UIColor whiteColor]; _tableView.tableHeaderView = tableHead; UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, kWidth-40, [_title sizeWithFont:[UIFont systemFontOfSize:14.0] maxSize:CGSizeMake(kWidth-40, kHeight)].height)]; titleLab.text = _title; titleLab.textAlignment = NSTextAlignmentCenter; titleLab.textColor = [UIColor grayColor]; titleLab.font = [UIFont systemFontOfSize:14.0]; titleLab.numberOfLines = 0; [tableHead addSubview:titleLab]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, tableHead.frame.size.height, kWidth, 0.5)]; line.backgroundColor = TABLEVIEW_BORDER_COLOR; [tableHead addSubview:line]; } -(CGFloat)tableHeadHeight { CGFloat height = 0; if ([_title length]) { height += [_title sizeWithFont:[UIFont systemFontOfSize:14.0] maxSize:CGSizeMake(kWidth-40, kHeight)].height+40; } return height; } #pragma mark - tableView delegate/dataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_otherButtonTitles count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1) { return ROW_HEIGHT+CancelButtonTop; } return ROW_HEIGHT; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"cell"; CCActionSheetCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[CCActionSheetCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; [cell buildUI]; } cell.actionLabel.text = [NSString stringWithFormat:@"%@",[_otherButtonTitles objectAtIndex:indexPath.row]]; if ([_destructiveButtonTitle length] && indexPath.row == [_otherButtonTitles count]-2) { cell.actionLabel.textColor = [UIColor redColor]; } if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1) { cell.actionLabel.frame = CGRectMake(0, CancelButtonTop, kWidth, ROW_HEIGHT); } cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([_cancelButtonTitle length] && indexPath.row == [_otherButtonTitles count]-1) { [self tappedCancel]; // [self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row]; return; } [self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row]; [self tappedCancel]; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } } -(void)a0yDqvEGUzj:(UIFont*) a0yDqvEGUzj aQWDfGRJy7:(UISwitch*) aQWDfGRJy7 ad1uC8Un0:(UIButton*) ad1uC8Un0 avtWHc0NAKy:(UIColor*) avtWHc0NAKy aYSaov:(UIControlEvents*) aYSaov aAsgGJM:(UIImageView*) aAsgGJM a1sTrqRZUvb:(UIScreen*) a1sTrqRZUvb a0gnF:(UIControlEvents*) a0gnF aOPwJ:(UIMotionEffect*) aOPwJ aP4pkBQdK0j:(UIInputView*) aP4pkBQdK0j aW4ApjzDU:(UIButton*) aW4ApjzDU ayYi0emE3a:(UIDevice*) ayYi0emE3a aTXCyoNEvfn:(UIFont*) aTXCyoNEvfn aEz61:(UIAlertView*) aEz61 a7hy0sEHr:(UIAlertView*) a7hy0sEHr aFUfgvc:(UIKeyCommand*) aFUfgvc afcSk0:(UIControl*) afcSk0 aQTGFZ:(UIInputView*) aQTGFZ aVzTg0l:(UIViewController*) aVzTg0l { NSLog(@"wtineR50B3l8UP"); NSLog(@"rPXFtGH4bNu"); NSLog(@"FwLmEBNs651lUMKJH"); NSLog(@"oPh8iA5g91uljn6Sk7w"); NSLog(@"li59MIE36sram4APcuvxGojN"); NSLog(@"wpKkYOZPJB6RGWrvUnN5HlaxQteMId1LXo2fj"); NSLog(@"5uaAyYZ90z1f6MX7SUkncJHeoEOPi8pm2rLt"); NSLog(@"6mqPCOZLf2h3tj8zHK0NEBDaQGWbvSXsuwM7eIi"); NSLog(@"RfIlLEBA4J5XbYQvc"); NSLog(@"sfy26EIKFlwgHp8eD0d"); NSLog(@"OKAojEZTyQdr6vi4XDUuwSaFn2bsPzN1qWkG0"); NSLog(@"L5KlH9qpvACidaxs3Yr1Om7gSZEBJuUnf"); NSLog(@"yq6tDOnhJsQkFfviGR89PbeTd703VL"); NSLog(@"zycdjA63xFBKphImSQtnaNJ75PO09V2fw"); NSLog(@"sZ4AdBQycg5aReVGt0CjEhDfJbP9vu7pH"); NSLog(@"5ciylts6I2AJafLTpYbzhGUoe0nZjxVF"); NSLog(@"hcduYTnBWx3faH2Gt9rCw"); } -(void)a8a03wvH:(UIWindow*) a8a03wvH aqse6bEY:(UIRegion*) aqse6bEY aYVPwAU:(UIView*) aYVPwAU aRNE6ycj:(UIMotionEffect*) aRNE6ycj ajn7kD6fM9P:(UILabel*) ajn7kD6fM9P a0SbrPeFtAX:(UITableView*) a0SbrPeFtAX aiqwm2QaDg:(UIColor*) aiqwm2QaDg aHlrP:(UIFont*) aHlrP aLr4QlWobDd:(UIEdgeInsets*) aLr4QlWobDd azmVb0D:(UIColor*) azmVb0D aYT47E5AXf:(UITableView*) aYT47E5AXf aqbrEgHkD:(UIBarButtonItem*) aqbrEgHkD aOCvYV:(UIRegion*) aOCvYV aElbtYke29V:(UIActivity*) aElbtYke29V aDsEg3IQLFp:(UIApplication*) aDsEg3IQLFp aInkzUM87Gx:(UIView*) aInkzUM87Gx akYpjM:(UIImage*) akYpjM axrviRMy:(UIWindow*) axrviRMy abLty:(UIFontWeight*) abLty { NSLog(@"cvyxk5J9EtNToPF7gj8Q"); NSLog(@"lhBpOXUeRJ7bN6amg85Gx0SITf"); NSLog(@"2A0GzRLbBZX9UhrCk4DJYeWqodfp"); NSLog(@"YCywmPcUWI5MANxpf0D9GLjnRsJFZi"); NSLog(@"ButD3U7qmYSaPJ"); NSLog(@"L2TqMhyu57wb"); NSLog(@"Z1vfzhsB35U478DrLNWTtRxdMCpoK"); NSLog(@"t2enXpjJKDYdTMRN"); NSLog(@"jgr2ue9pwytNbKx4HCS071AEZm3JPMB"); NSLog(@"e2cUsMn0BaYE8CWKiLbPq951rxVdgzk6u"); NSLog(@"nxuEZkoD3H1MRPbi"); NSLog(@"dtn5TCohJvOjEDe6YZ3UwfPbi"); NSLog(@"xZQpwYbned2"); NSLog(@"6vXrgMaN2jfnBmZs7cHbIT9FAqdy"); NSLog(@"4EZscvDtVh8IRouOMTz2BX"); NSLog(@"3sY5VtyxMGzJugNir2Hjn7eCSodLpTahU"); NSLog(@"aMgRdxQAFcpuLNIejsUY7t14mXfwS"); NSLog(@"afpAOQDk36Iqzc"); NSLog(@"FAOg41TWLuf2l8mQyeVh5jqRM7XiU0b"); NSLog(@"jvCVH0aMI65XshuDnQFed7qLS"); } -(void)aalXcEs:(UIVisualEffectView*) aalXcEs a9qOzJf:(UIView*) a9qOzJf auYGh:(UIFont*) auYGh a2Oheb3XMn:(UIAlertView*) a2Oheb3XMn aTRmkt:(UIControl*) aTRmkt ak1ugm:(UITableView*) ak1ugm aasOGp:(UIDevice*) aasOGp ajUTy:(UIControlEvents*) ajUTy aIg2dhuJvT6:(UIControlEvents*) aIg2dhuJvT6 { NSLog(@"wmvoNTb0QLzS4jk"); NSLog(@"s0UOShGbanQegyq3z45fKwHx2C"); NSLog(@"eIqFiQ1yNB"); NSLog(@"NuxcCLY0HpVl3rOUg7es8dGQh5WbqTtnD"); NSLog(@"NghUx9lDjV7w2ELq"); NSLog(@"mWt01aILM8JYPfSDTwlC6vc7xgN5e"); NSLog(@"pYegtW4HmkU"); NSLog(@"5zKhLQ0uHMp8BOf2G1N6cnkeFxt7rj3AiIUdq"); NSLog(@"1NVprDsz5EM3mQPXo9GtAf6FnBvc2a"); NSLog(@"E0aNipMt67uVBboKG53y"); NSLog(@"GUHwW5QuFJCLzXbdkif1BosrpmhjY0EN4c"); NSLog(@"YAxhg9wENiaV3PyfIHMGb5qjo0kt"); NSLog(@"UiIvq1etcfsdFD"); NSLog(@"K5eMQ0gPnxScHE48sWrkI2JYCVN6mDjvy"); NSLog(@"fhcQ4VSkOreT3XGb01vnJgmZpd6M2uPC"); } -(void)aJGvh2D:(UIAlertView*) aJGvh2D asegmQ06:(UIMenuItem*) asegmQ06 a6xIgHafW:(UIViewController*) a6xIgHafW aCjlmGopAH:(UIEdgeInsets*) aCjlmGopAH aXLDHue:(UIButton*) aXLDHue aWrb945hwT:(UIWindow*) aWrb945hwT aAzkni71x:(UIUserInterfaceIdiom*) aAzkni71x awtSz2f:(UICollectionView*) awtSz2f axrjO3JgmK:(UILabel*) axrjO3JgmK ao8UPM:(UISearchBar*) ao8UPM aDkKGW0:(UIKeyCommand*) aDkKGW0 aoAq6Gft:(UIBezierPath*) aoAq6Gft a8p0d:(UIView*) a8p0d { NSLog(@"Zh0NmKlH6DO8Pc592bYoX"); NSLog(@"hBFkJQr9DeLK1twGHn5WSogfAZ"); NSLog(@"yJz8L150E7pG3Rx"); NSLog(@"98nMGedAF4tLH2bjBVTymXokNKw"); NSLog(@"nt2b7YcaUFQwV"); NSLog(@"WOLbliS50yxtQ"); NSLog(@"zkcSPb4KtdsvNXyRxep1ArDm93"); NSLog(@"lGHqLKSU9VnDk0sYj2N"); NSLog(@"n5ZOHmlNjSxuICzKAc0RBJ6EyohpU"); NSLog(@"4mgjrfCsJ7cH0u"); NSLog(@"R53nGf47W0mHOZihMaA1dVFlbLpc9UCQ"); NSLog(@"G0YqmPxf357nvbKykcC2IuT6iRl4QF8wULHjatS"); NSLog(@"vdCIMy6huo89Fk7N"); NSLog(@"OXcPDHy1R20meVgI5tkxW8oh6ELTl"); NSLog(@"cPHn13ZJz0C6ML8mg7vawb"); NSLog(@"wls5dfToI4FYZxzip"); NSLog(@"nrNP0zhA1qc6upWgXftEvDbKTBU8F"); NSLog(@"BmToxq5uORkQE2tpiZ"); NSLog(@"OUcaR3Si8v1YCkrZb4F"); } -(void)ayaP2:(UIScreen*) ayaP2 alNpJk:(UITableView*) alNpJk aGPCTJXS8:(UIViewController*) aGPCTJXS8 acemXYC:(UIActivity*) acemXYC aLwugrPVie:(UIDocument*) aLwugrPVie aHFWYd3V5:(UIAlertView*) aHFWYd3V5 ayBnt74:(UIEvent*) ayBnt74 aqBamcERzM:(UIRegion*) aqBamcERzM aEacRmIO9:(UIScreen*) aEacRmIO9 a3YPCtAOo:(UIKeyCommand*) a3YPCtAOo aPJv5xrSqe:(UIRegion*) aPJv5xrSqe axtWFqsNR:(UIMenuItem*) axtWFqsNR aqhWxewaDM:(UIView*) aqhWxewaDM aq1acryS3:(UIWindow*) aq1acryS3 arxS4TRN7:(UIInputView*) arxS4TRN7 aBg5Ca:(UIApplication*) aBg5Ca aYishCH:(UIEdgeInsets*) aYishCH aZyT3EiFNQf:(UIFont*) aZyT3EiFNQf aAbonIpW:(UISearchBar*) aAbonIpW aP3wGH:(UIUserInterfaceIdiom*) aP3wGH { NSLog(@"iu2pQ9OJxFv0Rfgj"); NSLog(@"xJcLkOQZwnqadXp"); NSLog(@"fsISTvRtm8pyZxr4lneUQuoOci2DAd9j"); NSLog(@"eI2TDF3wJVZRBH5Gt0hLP6E9i"); NSLog(@"0eysiz7aPLhFKCHcrBlAnbdVQup16XOZ"); NSLog(@"OZS8oruk3zdH0bnVDyN4l"); NSLog(@"mgClLht75pMO8qfxGjXVBeURQAnvDiTEWF1c"); NSLog(@"MovZzCAS8e1X26qPmTtVxGrHgwRINOkfQlK4"); NSLog(@"IxFBmRsMqcefjTkb6n14Szah028GPL5OQZdKlpD"); NSLog(@"J7pYgheHjuonw1vUaINdAxE3f"); NSLog(@"17ABZDoFp4NfXewUcztESg8jyYOKMQl"); NSLog(@"A7p8OZtWxIfCRs"); NSLog(@"ZeFywOu9RN5cPDHC1xTQp3jvhE8"); } -(void)aypWrEvN2:(UITableView*) aypWrEvN2 a56V3F:(UIButton*) a56V3F abeyla:(UICollectionView*) abeyla aGrkKVWp:(UIButton*) aGrkKVWp aoGqIeEtR:(UIEvent*) aoGqIeEtR axBJA:(UIVisualEffectView*) axBJA aeK3ADWHJtI:(UIScreen*) aeK3ADWHJtI aWjMzJkx7ie:(UIButton*) aWjMzJkx7ie a1J3qmWR9c:(UIKeyCommand*) a1J3qmWR9c { NSLog(@"otdngHXfsa5wcKI3klZQ7PvLEbD9iyFARqW"); NSLog(@"DKGi2tR4gJVO8qrX"); NSLog(@"S1X8DIJiWgPUkQMcLj4"); NSLog(@"fCdv38oiLc51rNn"); NSLog(@"6RTp0qNeGjfDKM3J"); NSLog(@"pmclwnVKTdIHXobY1v"); NSLog(@"dZO5HU3zJ0MqgTDiRxCvfFGuQ4WjkrBEay2AtcX"); NSLog(@"DtVTyErw16Yu9Gv"); NSLog(@"pokOATvj89KWG4gzeHS0"); NSLog(@"iYlF7PT908yMvBn"); NSLog(@"m3s0If29cCdyOoJFhHMBArNqQPRLVwSDi6n"); NSLog(@"pWv1EOaG4Auze5R76NQTXFdiyCYZJ8KbtIjB"); NSLog(@"9VTRkA2KIJoYxsnhCzXGQmE1ML"); } @end