哈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;
这样就可以啦,
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;
这样就可以啦,
相关文章推荐
- IOS 如何给自定义按钮设置选中的效果
- 手机卫士学习06-自定义滚动的TextView实现走马灯效果
- UITableViewCell 自定义默认选中 和 改变cell背景图片
- IOS-通过自定义iCarousel来高仿土巴兔选择装修风格效果(中间选中项放大)
- Android ListView自定义和选中效果
- iOS UItableviewCell 自定义选中颜色及默认选中首行
- IOS-通过自定义iCarousel来高仿土巴兔选择装修风格效果(中间选中项放大)
- 关闭UITableViewCell选中效果
- UITableViewCell选中自定义的颜色
- Android自定义button的实现,未选中,按下,选中效果
- 自定义tabBarItem选中和未选中的显示效果
- 自定义UITableViewCell 的选中背景图片
- 【iOS学习笔记 15-11-06】简单自定义navigationcontroller push和pop动画效果
- 自定义UITableViewCell 的选中背景图片
- UITableViewCell添加自定义view,在cell选中高亮时,view消失,取消高亮时,view又出现
- Android自定义button的实现,未选中,按下,选中效果
- 自定义 UITableViewCell 无法选中 点击颜色不变
- 自定义UITableViewCell选中Subviews(例如UILabel)背景色发生改变
- 自定义UITableViewCell 的选中背景图片
- ios7适配--uitableviewcell选中效果