UItabBarController에서 텍스트 이미지 파란색 렌더링 제거

1675 단어
Tab Barcontroller에 있는.m 파일 중

+ (void)initialize
{
    //  appearance UITabBarItem 
    //  UI_APPEARANCE_SELECTOR ,  appearance 
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}

그림의 파란색 렌더링 효과 제거: 전송된 이미지 뒤에 mageWith Rendering Mode 추가: UIImage Rendering Mode Always Original
 vc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

예를 들면 다음과 같습니다.
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * nv = [[UINavigationController alloc]initWithRootViewController:vc];
    
    
    [self addChildViewController:nv];
    
    
    
}

좋은 웹페이지 즐겨찾기