harshiYL
harshiYL

Reputation: 251

How to change custom cell image and label font color when selected in uitableview?

I have a custom cell with imageview and label.When user selected a particular cell in the tableview I want change its image and the label font color.How can I do this ?I want to avoid that default way of cell selection(highlight cell in blue color) and use above method instead of that.

Upvotes: 0

Views: 1401

Answers (1)

bitmapdata.com
bitmapdata.com

Reputation: 9600

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

     MyCustomCell *selectedCell = (MyCustomCell *)[tableView cellForRowAtIndexPath:indexPath];

     //selectedCell.textLabel.textColor = <#your color#>
     //selectedCell.myImage = <#your image>

}

if you want changed selected cell backgroundColor, try to this.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString *cellId = @"cellIdentifier";

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
     if(!cell)
     {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

        UIView *bgColorView = [[UIView alloc] init];
        [bgColorView setBackgroundColor:[UIColor redColor]];
        [cell setSelectedBackgroundView:bgColorView];
     }
}

Upvotes: 2

Related Questions