
@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图标颜色?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)