目录
1. UITableViewCell取消点击高亮
2. UITableView取消选中状态
3. UITableView去除分割线
4. UICollectionViewCell选中高亮
4.1 控制代理方法
4.2 控制UICollectionViewCell
内容
1. UITableViewCell取消点击高亮
可以在tableView: cellForRowAtIndexPath:数据源方法中调用下面代码
cell.selectionStyle = UITableViewCellSelectionStyleNone;
自定义cell可以在cell中调用上述代码
2. UITableView取消选中状态
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//其他操作
// 取消选中状态
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
3. UITableView去除分割线
tableView.separatorStyle = UITableViewCellSeparatorStyleNone
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
若需要隐藏某个cell的分割线,而不是所有的,可以判断indexPath调用第二种方式
4. UICollectionViewCell选中高亮
4.1 控制代理方法
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = YouColor;
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
4.2 控制UICollectionViewCell
self.selectedBackgroundView = [[UIView alloc] init];
self.selectedBackgroundView.backgroundColor = YouColor;