objective-c – 如何更改默认蓝色的tabbar图标颜色?

objective-c – 如何更改默认蓝色的tabbar图标颜色?,第1张

概述我有四个标签.我能够将标签图标颜色默认的蓝色更改为红色(或者可能是任何颜色),并且它可以完美地运行.问题是它只适用于三个tabbaritems,最后一个默认为蓝色.以下是代码.我在rootviewcontrollerAppDelegate.m中对此进行编码您可以通过在appdelegate中粘贴以下代码来尝试此 *** 作.你们能帮助我吗?我会非常感激! @implementation UITabBar 我有四个标签.我能够将标签图标颜色从默认的蓝色更改为红色(或者可能是任何颜色),并且它可以完美地运行.问题是它只适用于三个tabbaritems,最后一个默认为蓝色.以下是代码.我在rootvIEwcontrollerAppDelegate.m中对此进行编码您可以通过在appdelegate中粘贴以下代码来尝试此 *** 作.你们能帮助我吗?我会非常感激!

@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- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:    (NSDictionary *)launchOptions {        [[tabbarController tabbar] recolorItemsWithcolor:[UIcolor redcolor] shadowcolor:[UIcolor blackcolor] shadowOffset:CGSizeMake(0.0f,-1.0f) shadowBlur:3.0f];    [self.window addSubvIEw:tabbarController.vIEw];        [self.window makeKeyAndVisible];        [self addTabBararrow];         return YES;}
解决方法 自我添加tabbar-item没问题,我测试了4个项目的代码;

但是你的最后一个tabbar项是一个系统tabbar项(“….”“more”项),所以这段代码可能没用;它只是没有使用你的设置图像;

总结

以上是内存溢出为你收集整理的objective-c – 如何更改默认蓝色的tabbar图标颜色?全部内容,希望文章能够帮你解决objective-c – 如何更改默认蓝色的tabbar图标颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1059070.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存