您的位置:首页 > 产品设计 > UI/UE

哈06-自定义UITableViewCell选中效果

2014-01-26 11:59 274 查看
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;
这样就可以啦,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: