Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3759920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:23:29+00:00 2026-05-19T10:23:29+00:00

I’m writing a custom UITabBar replacement, and I would like to know how to

  • 0

I’m writing a custom UITabBar replacement, and I would like to know how to recreate the filter that the built-in implementation does with the UITabBarItem image – that blue shining on selected tabs and gray gradient on unselected ones. I guess it’s a matter of using the source image alpha value as a mask and overlay it with a pre-made blue (or whatever color) shining image and another one grayed out, but I would like to know what is the best approach from a code point of view.

Best,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:23:30+00:00Added an answer on May 19, 2026 at 10:23 am

    Edit: Fixed up the blue filter a little
    Edit2: Cleaned up the grey filter

    I required code to do these effects, so I wrote a couple functions for them:

    UIImage *grayTabBarItemFilter(UIImage *image) {
        int width = image.size.width, height = image.size.height;
        UIImage *result = image;
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        if (colorSpace == NULL) {
            return result;
        }
        CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
        if (context == NULL) {
            CGColorSpaceRelease(colorSpace);
            return result;
        }
        CGFloat colors[8] = {80/255.0,80/255.0,80/255.0,1, 175/255.0,175/255.0,175/255.0,1};
        CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, NULL, 2);
        CGContextDrawLinearGradient(context, gradient, CGPointMake(0,-(32-height)/2.0), CGPointMake(0,height+(32-height)/2.0), 0);
        CGGradientRelease(gradient);
        CGContextSetBlendMode(context, kCGBlendModeDestinationIn);
        CGContextDrawImage(context, CGRectMake(0,0,width,height), image.CGImage);
        CGImageRef newImage = CGBitmapContextCreateImage(context);
        if (newImage != NULL) {
            result = [UIImage imageWithCGImage:newImage];
            CGImageRelease(newImage);
        }
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
        return result;
    }
    
    struct RGBA {
        unsigned char red;
        unsigned char green;
        unsigned char blue;
        unsigned char alpha;
    };
    
    #define BLUE_ALPHA_THRESHOLD 128
    #define BLUE_BRIGHTNESS_ADJUST 30
    
    UIImage *blueTabBarItemFilter(UIImage *image) {
        int width = image.size.width,
            height = image.size.height;
        UIImage *result = image;
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        if (colorSpace == NULL) {
            return result;
        }
        CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
        if (context == NULL) {
            CGColorSpaceRelease(colorSpace);
            return result;
        }
        UIImage *gradient = [UIImage imageNamed:@"selection_gradient.png"];
        CGContextDrawImage(context, CGRectMake(-(gradient.size.width - width) / 2.0, -(gradient.size.height - height) / 2.0, gradient.size.width, gradient.size.height), gradient.CGImage);
        CGContextSetBlendMode(context, kCGBlendModeDestinationIn);
        CGContextDrawImage(context, CGRectMake(0,0,width,height), image.CGImage);
        struct RGBA *pixels = CGBitmapContextGetData(context);
        if (pixels != NULL) {
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int offset = x+y*width;
                    if (pixels[offset].alpha >= BLUE_ALPHA_THRESHOLD && 
                        ((x == 0 || x == width-1 || y == 0 || y == height-1) ||
                         (pixels[x+(y-1)*width].alpha < BLUE_ALPHA_THRESHOLD) ||
                         (pixels[x+1+y*width].alpha < BLUE_ALPHA_THRESHOLD) ||
                         (pixels[x+(y+1)*width].alpha < BLUE_ALPHA_THRESHOLD) ||
                         (pixels[x-1+y*width].alpha < BLUE_ALPHA_THRESHOLD))) {
                        pixels[offset].red = MIN(pixels[offset].red + BLUE_BRIGHTNESS_ADJUST,255);
                        pixels[offset].green = MIN(pixels[offset].green + BLUE_BRIGHTNESS_ADJUST,255);
                        pixels[offset].blue = MIN(pixels[offset].blue + BLUE_BRIGHTNESS_ADJUST,255);
                    }
                }
            }
            CGImageRef image = CGBitmapContextCreateImage(context);
            if (image != NULL) {
                result = [UIImage imageWithCGImage:image];
                CGImageRelease(image);
            }
        }
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
        return result;
    }
    

    To make the blue filter effect work you’ll need to include this image in your project as “selection_gradient.png”: selection_gradient.png

    Also, you may want to play with the defines to get the effect exactly how you like, I didn’t take much time to perfect them, though they look good enough to me.

    Of course I don’t know the exact filters that Apple applied, but I “guestimated” them and they look alright to me. I’m not sure if these functions are iPhone 4 compatible because I’m only using them in an iPad app, but it wouldn’t be hard to edit them to your liking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.