How to change tabbar icon color from default blue?

≡放荡痞女 提交于 2019-12-04 04:51:40

no problem for self-add tabbar-item, i test this code for 4 items;

but your last tabbar item is a system tabbar item(the"....""more" item), so this code maybe has no use for it; its just not use image your set in;

 [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
mcsquare

Thanks for your sharing.

But there are some flaws where deploying on iPhone4 or iPod4 which have retina display. The selected icon in the tarBar will be smaller than the unselected one.

So I would like to share my fix here:

CGSize orginalSize = [[item selectedImage] size];
double scaleFactor = 1;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    scaleFactor = [[UIScreen mainScreen] scale];
}
    contextRect.size = CGSizeMake(orginalSize.width*scaleFactor, orginalSize.height*scaleFactor);

// Retrieve source image and begin image context
UIImage *itemImage = [item image];
double imageScale = 1;
if ([itemImage respondsToSelector:@selector(scale)]) {
    imageScale = itemImage.scale;
}
CGSize itemImageSize = CGSizeMake(itemImage.size.width*imageScale, itemImage.size.height*imageScale);

If I am wrong, please free fee to let me know :)

@implementation MoreViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"More";
        self.tabBarItem.image=[UIImage imageNamed:@"more.png"]; // here more.png is Yellow Image
    }
    return self;
}

//.......
@end

go to your asset folder, find the asset and click on Identity Inspector , and change "Render As" to Original Image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!