你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 修改 TableView 的 delete 按鈕

iOS 修改 TableView 的 delete 按鈕

編輯:IOS開發綜合
在iOS 6 以前重寫

-(void)willTransitionToState:(UITableViewCellStateMask)state ,發現iOS7 以前的方法不管用了


iOS7 下

在自定義cell裡重寫

-(void)willTransitionToState:(UITableViewCellStateMask)state{

[super willTransitionToState:state];

if((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask){

// [self recurseAndReplaceSubViewIfDeleteConfirmationControl:self.subviews];

[self performSelector:@selector(recurseAndReplaceSubViewIfDeleteConfirmationControl:) withObject:self.subviews afterDelay:0];

}

}


-(void)recurseAndReplaceSubViewIfDeleteConfirmationControl:(NSArray*)subviews{

NSString *delete_button_name = @"delete";

for (UIView *subview in subviews)

{

/**

* iOS 6 以前

*/

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])

{

/**

將添加一個視圖來覆蓋默認的控制使用的圖像有一個透明的背景

*/

UIView *backgroundCoverDefaultControl = [[UIView alloc] initWithFrame:CGRectMake(0,0, 64, 33)];

[backgroundCoverDefaultControl setBackgroundColor:[UIColor whiteColor]];

[[subview.subviews objectAtIndex:0] addSubview:backgroundCoverDefaultControl];

UIImage *deleteImage = [UIImage imageNamed:delete_button_name];

UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,deleteImage.size.width, deleteImage.size.height)];

[deleteBtn setImage:[UIImage imageNamed:delete_button_name]];

[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];

}

/**

* ios7

*/

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"])

{

UIButton *deleteButton = (UIButton *)subview;

[deleteButton setImage:[UIImage imageNamed:delete_button_name] forState:UIControlStateNormal];

[deleteButton setTitle:@"" forState:UIControlStateNormal];

[deleteButton setBackgroundColor:[UIColor clearColor]];

for(UIView* view in subview.subviews){

if([view isKindOfClass:[UILabel class]]){

[view removeFromSuperview];

}

}

}

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"])

{

for(UIView* innerSubView in subview.subviews){

if(![innerSubView isKindOfClass:[UIButton class]]){

[innerSubView removeFromSuperview];

}

}

}

if([subview.subviews count]>0){

[self recurseAndReplaceSubViewIfDeleteConfirmationControl:subview.subviews];

}

}

}



  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved