Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIBarButtonItem tintcolor to non default UIColor

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?

like image 623
jimmy Avatar asked Oct 31 '22 08:10

jimmy


1 Answers

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];
like image 158
jimmy Avatar answered Nov 11 '22 03:11

jimmy