0

Here's the problem:

I have a tab bar controller customized so the tab item highlights are yellow instead of the default blue. What's wrong is that the "More" item comes up because I have too many tab items (removing them is not really an option), and this "more" is still blue.

I used classes I got from the internet to implement the customization. Here is the code:

// UITabBar+ColorExtensions.m

@implementation UITabBar (ColorExtensions)

- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur
{

CGColorRef cgColor = [color CGColor];
CGColorRef cgShadowColor = [shadowColor CGColor];
for (UITabBarItem *item in [self items])
    if ([item respondsToSelector:@selector(selectedImage)] &&
        [item respondsToSelector:@selector(setSelectedImage:)] &&
        [item respondsToSelector:@selector(_updateView)])
    {
        CGRect contextRect;
        contextRect.origin.x = 0.0f;
        contextRect.origin.y = 0.0f;
        contextRect.size = [[item selectedImage] size];
        // Retrieve source image and begin image context
        UIImage *itemImage = [item image];
        CGSize itemImageSize = [itemImage size];
        CGPoint itemImagePosition; 
        itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width) / 2);
        itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height) / 2);
             UIGraphicsBeginImageContext(contextRect.size);
            CGContextRef c = UIGraphicsGetCurrentContext();

        // Setup shadow
        CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);

        // Setup transparency layer and clip to mask
        CGContextBeginTransparencyLayer(c, NULL);
        CGContextScaleCTM(c, 1.0, -1.0);
        CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);

        // Fill and end the transparency layer
        CGContextSetFillColorWithColor(c, cgColor);
        contextRect.size.height = -contextRect.size.height;
        CGContextFillRect(c, contextRect);
        CGContextEndTransparencyLayer(c);

        // Set selected image and end context
        [item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];
        UIGraphicsEndImageContext();

        // Update the view
        [item _updateView];
    }
}

@end

and the controller:

@implementation AATabBarController

- (void)viewDidLoad {
[super viewDidLoad];

// Put in a background
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, 48);
backgroundView = [[UIView alloc] initWithFrame:frame];

[backgroundView setBackgroundColor:[UIColor colorWithRed:0.0
                                             green:0.0
                                              blue:0.0
                                             alpha:0.1]];
[self.tabBar insertSubview:backgroundView atIndex:0];
}

-(void)dealloc {
[backgroundView release];

[super dealloc];
}

-(void)updateTabColor:(UIColor *)color {
// Recolor the tab bar
[self.tabBar recolorItemsWithColor:color shadowColor:[UIColor blackColor] shadowOffset:CGSizeMake(0.0f, -1.0f) shadowBlur:3.0f]; 
}

-(void)updateBackgroundColor:(UIColor *)color {
// Update the background color
[backgroundView setBackgroundColor:color];
}

@end

Does anyone know what I should do so the "more" tab item is the customized color?

Caleb
  • 124,013
  • 19
  • 183
  • 272
jylee
  • 833
  • 2
  • 8
  • 15

1 Answers1

1

That code looks very similar to the code in this question. I know you're asking a different question here (the linked Q asks "will my app be rejected" to which the answer is "yes"). Nevertheless, you're using the same private UITabBarItem methods, so it's unlikely that anyone can give you a reliable answer.

Community
  • 1
  • 1
Caleb
  • 124,013
  • 19
  • 183
  • 272