0

I know it's probably a duplicate, but I want to know the best and the fastest way to change the blue highlight color when a cell is selected.

Of curse, I already tried (and it works) the way which consist in change the background color when the cell is selected (like this thread) but I don't like this way, I would prefer to really change this highlight color.

Any link or idea ? Thanks.

Community
  • 1
  • 1
Lucien
  • 451
  • 4
  • 16

5 Answers5

7

inside tableview's

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Create a uiimageview and change it's background color to your desired color

if (cell == nil) {
    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor greenColor];
    cell.selectedBackgroundView = bgView;
}
manujmv
  • 6,450
  • 1
  • 22
  • 35
2

If you are creating your table view cell using nib, then in attributes inspector of cell, you can see a attribute "selection". set this to none.

if ur creating programmatically, then set your cell as

yourCell.selectionStyle = UITableViewCellEditingStyleNone;
Rajath Shetty K
  • 424
  • 3
  • 9
0

First you have to create a view with same size of the cell. Apply background color to that view. Then set the view as the selected background of your cell in cellForRowAtIndexpath delegate method.

[cell setSelectedBackgroundView:yourView];
Augustine P A
  • 5,008
  • 3
  • 35
  • 39
0

Write these line in this method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath



if (cell == nil) 
{
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];

    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView  = bgView;
}
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0

You can assign new UIView to cell's selectedBackgroundView with desired color. Swift 3

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "departmentCell", for: indexPath)

        let selectedView = UIView(frame: cell.frame)
        selectedView.backgroundColor = ColorKit.cellSelectionColor
        cell.selectedBackgroundView = selectedView



        return cell
    }
Rajan Twanabashu
  • 4,586
  • 5
  • 43
  • 55