Change chevron color by replacing it in modifyCell with new sf symbol chevron.right

826 Views Asked by At

Id like to use the system image chevron.right for my accessory icon and replace what is currently there so I can control the color. Right now with iOS 13+ the tint color is not updating like the text is, previous versions work. I need this done in objective c, not swift, using the system image sf symbol chevron.right.

- (void)modifyCell:(UITableViewCell*)tableCell andIndex:(NSIndexPath *)indexPath {

    Event *event = [self findDataInRow:[self findRow:indexPath]];

    if(event != nil)
    {
        EventsTableViewCell *eventTableCell = (EventsTableViewCell *)tableCell;

        if(eventTableCell != nil)
        {

        }
    }
1

There are 1 best solutions below

1
Warren Burton On BEST ANSWER

You need to manipulate the color of the accessoryView of the dequeued UITableViewCell when you return the cell in:

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

So in a simple datasource implementation.

@implementation XViewController

- (UIColor *)colorForIndex:(NSInteger)index {
    NSArray *colors = @[UIColor.redColor,UIColor.greenColor,UIColor.blueColor];
    return colors[index % 3];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.tintColor = [UIColor orangeColor];
}


- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    cell.textLabel.text = @"hello world";
    cell.imageView.image = [UIImage systemImageNamed:@"pencil.slash"];
    UIImageView *accessory = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"pencil.and.outline"]];
    accessory.tintColor = [self colorForIndex:indexPath.row];
    cell.accessoryView = accessory;

    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}


@end

Pick your favoured system image instead of "pencil.and.outline" which is just there to prove that it isn't the standard chevron. Observe that the LHS cell image takes the view tint of orange and the accessory view on RHS takes any color that you wish.

enter image description here