美文网首页
iOS关于cell点击更换背景颜色

iOS关于cell点击更换背景颜色

作者: AlenChen | 来源:发表于2016-06-17 20:46 被阅读1076次

具体的步骤是三个,第一步设定cell选择状态下的背景view

// cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.selectedBackgroundView= [[UIViewalloc]initWithFrame:cell.frame];

cell.selectedBackgroundView.backgroundColor= [UIColororangeColor];

此时记得不要设置点击类型为none

第二步在didSelectRowAtIndexPath的选择方法里面执行下面代码,这句代码是用来延迟执行的,因为我的需求是点击后变回原样

[selfperformSelector:@selector(cancleSelect)withObject:nilafterDelay:0.1f];

它的意思是将会在你执行完点击cell的方法后,0.1秒后执行下面一个方法

- (void)cancleSelect

{

[self.tableViewdeselectRowAtIndexPath:[self.tableViewindexPathForSelectedRow]animated:YES];

}

这样就可以达到点击cell变色,放开后恢复的效果了

相关文章

网友评论

      本文标题:iOS关于cell点击更换背景颜色

      本文链接:https://www.haomeiwen.com/subject/ramvdttx.html