5
votes

I've looked through all the typical navigation bar tintcolor tutorials and questions. I have a set tint for the navigation bar, but I have a mail icon that needs to change to a custom color when there is mail. (like reddit orange mail icon)

I can set the tint properly only when using system UIColors.

self.leftNavigationBarButton = [[UIBarButtonItem alloc] initWithImage:someImage style:UIBarButtonItemStylePlain target:self action:@selector(foo:)];
self.navigationItem.leftBarButtonItem = self.leftNavigationBarButton;

self.leftNavigationBarButton.tintcolor = [UIColor redColor];

However if I then use a custom color.

self.leftNavigationBarButton.tintcolor = [UIColor colorWithRed:100 green:40 blue:20 alpha:1.0];

It makes the icon white. Does anyone know what's going on or how I can use a custom color?

1

1 Answers

2
votes

I figured it out from this answer https://stackoverflow.com/a/5642229/1732711.

Short answer is to divide the RGB values by 255.0.

self.leftNavigationBarButton.tintcolor = [UIColor colorWithRed:100/255.0 green:40/255.0 blue:20/255.0 alpha:1.0];