Skip to content

Commit

Permalink
add new pro
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmoo committed Mar 24, 2016
1 parent d1ba1de commit a17a006
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
8 changes: 5 additions & 3 deletions CCActionSheet/CCActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ typedef enum : NSUInteger {
@property (strong,nonatomic) NSString *cancelText;

@property (weak, nonatomic) id<CCActionSheetDelegate> delegate;

//最多可显示maxcount个cell的高度
@property (assign, nonatomic) CGFloat maxCount;
//cell的样式,有两种:一种居中显示,另一种左对齐显示并带有icon
Expand All @@ -66,7 +65,7 @@ typedef enum : NSUInteger {
* @param cancelButtonTitle 取消按钮标题
* @param otherButtonTitles 其他按钮标题
*
* @return PQActionSheet
* @return ActionSheet
*/
- (instancetype)initWithTitle:(NSString *)title
delegate:(id<CCActionSheetDelegate>)delegate
Expand All @@ -83,14 +82,17 @@ typedef enum : NSUInteger {
* @param cancelButtonTitle 取消按钮标题
* @param otherButtonTitles 其他按钮标题
*
* @return PQActionSheet
* @return ActionSheet
*/
- (instancetype)initWithTitle:(NSString *)title
clickedAtIndex:(ClickedIndexBlock)block
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...;


//直接添加自定义视图
- (instancetype)initWithCustomView:(UIView *)customView;


/**
* @brief 显示ActionSheet
Expand Down
48 changes: 42 additions & 6 deletions CCActionSheet/CCActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ @interface CCActionSheet () <UITableViewDelegate,UITableViewDataSource>
@property (assign,nonatomic) CGFloat tableViewHeight;
@property (assign,nonatomic) NSInteger buttonCount;

@property (strong,nonatomic) UIView *customView;

@end

@implementation CCActionSheet
Expand Down Expand Up @@ -94,6 +96,16 @@ - (instancetype)initWithTitle:(NSString *)title
return self;
}

//添加自定义视图
- (instancetype)initWithCustomView:(UIView *)customView{
self = [super init];
if (self) {
self.customView = customView;
[self installSubViews];
}
return self;
}

- (void)dealloc {

[[NSNotificationCenter defaultCenter] removeObserver:self];
Expand All @@ -110,6 +122,7 @@ - (void)show
[[UIApplication sharedApplication].keyWindow addSubview:self];

self.tableView.frame = CGRectMake(0.0f,self.bounds.size.height, self.bounds.size.width, self.tableViewHeight);
NSLog(@"%@",self.tableView);
__weak typeof(self) weakSelf = self;

if([_delegate respondsToSelector:@selector(willPresentActionSheet:)]) {
Expand Down Expand Up @@ -266,6 +279,11 @@ - (UIView *)selectedView{
*/
-(CGFloat)tableViewHeight {

if (self.customView) {
NSLog(@"%f",self.customView.bounds.size.height);
return self.customView.bounds.size.height;
}

CGFloat tableHeight = 0.0f;

if (_maxCount) {
Expand Down Expand Up @@ -312,12 +330,19 @@ -(NSInteger)buttonCount {
#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

return ACTION_SHEET_BTN_HEIGHT;
if (self.customView) {
return self.customView.bounds.size.height;
}

return ACTION_SHEET_BTN_HEIGHT;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

if (self.customView) {
return 0.0f;
}

if(section == 0 && self.titleText) {

return ACTION_SHEET_BTN_HEIGHT;
Expand Down Expand Up @@ -429,14 +454,21 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
cell.sheetStyle = (CCActionSheetCellStyle)self.style;
}
cell.boundsTableView = self.tableView;
// 加上分割线
UIImageView *sepLine = [[UIImageView alloc]initWithImage:[self imageWithUIColor:[UIColor grayColor]]];
sepLine.frame = CGRectMake(0, ACTION_SHEET_BTN_HEIGHT - 0.3f, [UIScreen mainScreen].bounds.size.width, 0.3f);
[sepLine setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[cell addSubview:sepLine];

if (!self.customView) {
// 加上分割线
UIImageView *sepLine = [[UIImageView alloc]initWithImage:[self imageWithUIColor:[UIColor grayColor]]];
sepLine.frame = CGRectMake(0, ACTION_SHEET_BTN_HEIGHT - 0.3f, [UIScreen mainScreen].bounds.size.width, 0.3f);
[sepLine setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[cell addSubview:sepLine];
}
}

if(indexPath.section == 0){
if (indexPath.row == 0 && self.customView) {
self.customView.center = CGPointMake(self.tableView.bounds.size.width/2,self.tableView.bounds.size.height/2);
[cell.contentView addSubview:self.customView];
}
if (_iconImageNameArray.count > indexPath.row) {
cell.iconImageName = _iconImageNameArray[indexPath.row];
}
Expand Down Expand Up @@ -469,6 +501,10 @@ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

if (self.customView) {
return 1;
}

if(section == 0) {

return self.otherButtons.count;
Expand Down
17 changes: 17 additions & 0 deletions Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,26 @@ - (IBAction)showCCActionSheet:(UIButton *)sender {

sheet.iconImageNameArray = @[@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected",@"icon_connected"];

// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
// view.backgroundColor = [UIColor redColor];
// UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// button.frame = CGRectMake(0, 0, 50, 30);
// button.backgroundColor = [UIColor redColor];
// [button setTitle:@"click" forState:UIControlStateNormal];
// [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
// [view addSubview:button];



// CCActionSheet *sheet = [[CCActionSheet alloc] initWithCustomView:view];

[sheet show];
}

- (void)buttonClicked{
NSLog(@"11111");
}

- (void)cc_actionSheetDidSelectedIndex:(NSInteger)index{
NSLog(@"selected index:%ld",(long)index);
}
Expand Down

0 comments on commit a17a006

Please sign in to comment.