4 개의 탭이 있습니다. 탭 아이콘 색상을 기본 파란색에서 빨간색 (또는 아마 모든 색상)으로 변경할 수 있었으며 완벽하게 정상적으로 작동합니다. 문제는 3 개의 tabbaritem에 대해서만 작동하며 마지막 하나는 기본 파란색입니다. 아래는 코드입니다. 나는 이것을 다음과 같이 코딩하고있다 rootviewcontrollerAppDelegate.m
당신은 당신의 appdelegate에서 아래의 코드를 붙여 넣어 이것을 시도 할 수있다. 너희들이 나를 도와 주면 내가 너무 위대 할거야!기본 파란색에서 tabbar 아이콘 색을 변경하는 방법?
@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;
}
감사합니다 ... 나는 다른 문제에 봉착했습니다. 위의 코드는 단지 하나의 응용 프로그램에서만 작동했습니다. 다른 응용 프로그램에서 같은 코드를 시도했는데 ... cud u가이 물건을 시도합니다. 아마도 ... 다른 응용 프로그램에서 ... 그리고 나에게 답장해라. – kingston