哈06-自定义UITableViewCell选中效果

1、首先设置

xxxxtableview.separatorStyle=UITableViewCellSelectionStyleNone;

不然cell被重用后,会被还原为默认选中效果

2、在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中设置

cell.selectedBackgroundView=nil;

这步非常关键不然,之后后出现两个被选中的cell,

3在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{中自定义选中效果,以及其他其他需要

例如:

UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];


UIImageView *bgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"selected_bg"]];

        bgView.frame=CGRectMake(10, 0, kDeviceWidth-100, cell.frame.size.height);

        bgView.contentMode=UIViewContentModeScaleAspectFit;

       cell.selectedBackgroundView=bgView;

4、在

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath同时也设置

UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];


cell.selectedBackgroundView=nil;

这样就可以啦,


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值