UITableView滑动删除按钮样式改变
如图[默认样式],当cell中包含间隔区域时,使用系统默认滑动删除样式,会发现删除按钮会占位间隔区。
- #import "CcMyCarModelsViewController.h"
- @interface CcMyCarModelsViewController () <UITableViewDelegate, UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @implementation CcMyCarModelsViewController
- #pragma mark - UITableView滑动删除
- // 先要设Cell可编辑
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- // 定义编辑样式
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
- return UITableViewCellEditingStyleDelete;
- }
- // 进入编辑模式,按下出现的编辑按钮后,进行删除操作
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- /*
- [_dataMArr removeObjectAtIndex:indexPath.row];
- [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
- [_tableView reloadData];
- */
- }
- }
- // 修改编辑按钮文字
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
- return @"删除";
- }
- @end
[默认样式]
在自定义cell中覆盖方法:
- #import "CcMyCarModelsCell.h"
- @implementation CcMyCarModelsCell
- // 改变滑动删除按钮样式
- - (void)layoutSubviews {
- [super layoutSubviews];
- for (UIView *subView in self.subviews){
- if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
- CGRect cRect = subView.frame;
- cRect.size.height = self.contentView.frame.size.height - 10;
- subView.frame = cRect;
- UIView *confirmView=(UIView *)[subView.subviews firstObject];
- // 改背景颜色
- confirmView.backgroundColor=[UIColor colorWithRed:254/255.0 green:85/255.0 blue:46/255.0 alpha:1];
- for(UIView *sub in confirmView.subviews){
- if([sub isKindOfClass:NSClassFromString(@"UIButtonLabel")]){
- UILabel *deleteLabel=(UILabel *)sub;
- // 改删除按钮的字体
- deleteLabel.font=[UIFont boldSystemFontOfSize:15];
- // 改删除按钮的文字
- deleteLabel.text=@"删除";
- }
- }
- break;
- }
- }
- }
- @end
[改变滑动删除按钮样式]

浙公网安备 33010602011771号