一、点击时状态
1、不显示选中状态
cell.selectionStyle = UITableViewCellSelectionStyleNone;
2、点击时的颜色
typedef NS_ENUM(NSInteger, UITableViewCellSelectionStyle) {
UITableViewCellSelectionStyleNone, // 无色
UITableViewCellSelectionStyleBlue, // 蓝色
UITableViewCellSelectionStyleGray, // 灰色
UITableViewCellSelectionStyleDefault NS_ENUM_AVAILABLE_IOS(7_0)
};
二、点击时动画
1、正常点击(选中的图层不覆盖图片)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
2、特殊点击(选中的图层覆盖图片)
/** 在Cell中进行设置 */
// 申明选中时覆盖的view
@property (strong, nonatomic) UIView *selectView;
// 对高亮状态进行设置
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
_selectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.1];
}
else {
_selectView.backgroundColor = [UIColor clearColor];
}
}
三、侧滑删除样式
1、系统删除样式
/** 设置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
{
// 执行删除操作
}
/** 设置title文字 */
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
2、自定义删除样式
/** 侧滑删除按钮 */
- (NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"删除"
handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self tableView:tableView
commitEditingStyle:UITableViewCellEditingStyleDelete
forRowAtIndexPath:indexPath];
}];
rowAction.backgroundColor = [UIColor lightGrayColor]; // 设置颜色
NSArray *arr = @[rowAction];
return arr;
}
/** 侧滑删除按钮 执行 */
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// 执行删除操作
}