iPhone:Color of TabBar image?
I have added an image(Orange color) to TabBar, but when I run application image开发者_运维技巧 shown gray ! How can I slove this problem ? thanks
The color is fixed to blue. You could either try to write your own custom tab bar interface, or hack together something to place custom icons over the tab bar in a subclassed UITabBarController
, like this:
-(void)setActiveCustomOverlay
{
if ( self.activeOverlay )
{
[self.activeOverlay removeFromSuperview];
}
NSString *imagename = [NSString stringWithFormat:@"tab_%d.png",
[self selectedIndex]];
UIImage *img = [UIImage imageNamed:imagename];
self.activeOverlay = [[[UIImageView alloc] initWithImage:img] autorelease];
self.activeOverlay.frame = CGRectMake(2.0f+64.0f*[self selectedIndex],3.0f,60.0f,44.0f);
[tabbar addSubview:activeOverlay];
[tabbar bringSubviewToFront:activeOverlay];
}
And also do this:
- add a
UIView
property (nonatomic, retain) calledactiveOverlay
- add a
tabbar
property and hook it to the tab bar in IB - call
setActiveCustomOverlay
whenever the tab changes.
This is an ugly hack, but the easiest fix to implement in existing projects. Apple will not reject it either.
For iPad you need to tweak the numbers, and use wider tab bar images.
The tab bar image color cannot be changed, it should be always be in the default color. Do read the Human interface guidelines of ios for more details.
精彩评论