iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – 如何更改默认蓝色的tabbar图标颜色?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

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

@H_502_11@@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图标颜色?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。