Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change checkmark color in UITableView editing-mode?

After searching all over internet for a long time, but not getting the appropriate answer. I am putting the UITableView in editing mode and selecting multiple rows at a time. It is working great, but I wanted to change the color of checkmark from red to blue same as it is in the iPhone email app.

Any help would be appreciated.

Edited Version:

Here is my code...

in my ViewDidLoad function:

- (void)viewDidLoad
{
   ...

   [deviceTableVIew setAllowsSelectionDuringEditing:YES];
   [deviceTableVIew setAllowsMultipleSelectionDuringEditing:YES];

   [super viewDidLoad];
}

I have two UIButtons whhich set the editing mode for the tableview as follows:

-(IBAction)control:(id)sender{
   btnControl.enabled = false;
   btnControl.hidden = true;        
   btnCancel.enabled = true;
   btnCancel.hidden = false;    
   stateToggleToolbar.hidden = false;    
   [self.deviceTableVIew setEditing:YES animated:YES];
}

-(IBAction)cancel:(id)sender{
   btnCancel.enabled = false;
   btnCancel.hidden = true;
   btnControl.enabled = true;
   btnControl.hidden = false;    
   stateToggleToolbar.hidden = true;
   [self.deviceTableVIew setEditing:NO animated:YES];
}

The UITableView delegate methods are:

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

   //setting up the cells here

   return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
     ...

     if ([tableView isEditing] == YES) {
       // Do Nothing
     }else{
       [self.navigationController pushViewController:viewController animated:YES];
     }

  }

  -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

  }

  - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

      return 3;
  }
like image 575
Hassam Avatar asked Apr 30 '12 06:04

Hassam


1 Answers

One line solution is here)

Just set cell tintColor in your cellForRow:atIndexPath method.

cell.tintColor = UIColor.red

Below is swift code:

func tableView(tableView: UITableView,
        cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell 

{

    //get cell to configure from tableView
    let cell = tableView.dequeueReusableCellWithIdentifier("myCellIdentifier", forIndexPath: indexPath) as UITableViewCell

    //This line will change checkmark color of your awesome cell
    cell.tintColor = UIColor.redColor()

    // Configure cell  
    // ...

    //work is done! Let put the cell back to the tableView))
    return cell
}

And this is the result of selected and not selected cells:enter image description here:

like image 119
Nikolay Shubenkov Avatar answered Oct 23 '22 01:10

Nikolay Shubenkov