2011-06-30 5 views
0

は、ここで問題です:タブバーコントローラのカスタマイズと「もっと」問題

私はタブ項目のハイライトではなく、デフォルトの青の黄色になるようにカスタマイズタブバーコントローラを持っています。間違っているのは、タブ項目が多すぎる(削除することは実際には選択できない)ため、「More」項目が表示され、この「more」項目はまだ青です。

カスタマイズを実装するためにインターネットから入手したクラスを使用しました。ここでは、コードは次のようになります。

// 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 

とコントローラ:

@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 

誰もが、私は "もっと" タブ項目があるので、何をすべきかを知っていますカスタマイズされた色?

答えて

1

そのコードはthis questionのコードと非常によく似ています。私はあなたがここで別の質問をしていることを知っています(リンクされたQは答えが "はい"である "私のアプリは拒否される"と尋ねます)。それにもかかわらず、あなたは同じプライベートなUITabBarItemメソッドを使用しているので、誰もあなたに信頼できる答えを与えることはほとんどありません。

関連する問題