1

I was using the selectedImageTintColor property in my TabBarController to change the color of the selected TabBarItem.

The problem is that the color you set as tintcolor is not the final color applied, before it is changed (it gets some kind of gradient)

My question is, is it possible to find the color to apply as tintcolor to obtain a final color you know?

For example, I want my selected item to have a final color of

[UIColor colorWithRed:(154.0/255.0) green:(213.0/255.0) blue:(0.0) alpha:(1.0)

What are the color RGBs I should set to the property selectedImageTintColor?

pirho
  • 11,565
  • 12
  • 43
  • 70
pdrcabrod
  • 1,467
  • 1
  • 14
  • 22
  • If I understand you probably you want to prevent the gradient. Try this http://stackoverflow.com/questions/1355480/preventing-a-uitabbar-from-applying-a-gradient-to-its-icon-images – Popeye Jan 21 '13 at 16:01
  • You did, but I rather prefer to "counter" the gradient if possible – pdrcabrod Jan 21 '13 at 16:58

2 Answers2

0

As already stated by Ankit, your best bet is to use

- (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage

However, I appreciate you need to have a UIImage to be able to do this. If your designer can't provide you with this, what you can do is to draw your own UIImage in code as such.

- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

Obviously this code doesn't draw you a gradient, but it shows you the basics of drawing a UIImage. I'd have a look at a tutorial like the following to work out how to draw the exact gradient you want:

http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

JonB
  • 4,422
  • 2
  • 27
  • 25
-1

iOS does not provide an api for modifying the tint color gradient. However apple documentation suggests to use setFinishedSelectedImage:withFinishedUnSelectedImage: method.

see more in UITabBarItem reference

meaning-matters
  • 21,929
  • 10
  • 82
  • 142