UITableView的cell默认选中效果为:选中时cell变灰,有些时候不需要这个选中效果,或者需要其他的效果,以下介绍几种方法:
1、方法一:可以通过更改UITableViewCell提供的selectionStyle属性进行设置(貌似只有none和default两种style可用):
cell.selectionStyle = UITableViewCellSelectionStyleNone;
当然,这个属性的其他值为
UITableViewCellSelectionStyleNone,//无色,有效
UITableViewCellSelectionStyleBlue,//蓝色,没效果
UITableViewCellSelectionStyleGray,//灰色,没效果
UITableViewCellSelectionStyleDefault NS_ENUM_AVAILABLE_IOS(7_0)//默认
方法二:通过UITableView进行设置:
tableView.allowsSelection = NO;
2、自定义选中背景颜色
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor redColor];