iOS TabbarController 設置底部Toolbar圖片和文字顏色選中樣式


提取公共方法:

-(void)createChildVcWithVc:(UIViewController *)vc Title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    
    //圖片渲染
    vc.tabBarItem.title=title;
    vc.navigationItem.title=title;
    vc.tabBarItem.image=[UIImage imageNamed:image];
    vc.tabBarItem.selectedImage=[[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //文字渲染
    NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName]=[UIColor blackColor];
    [vc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateNormal];
    
    //選中的文字渲染
    dict[NSForegroundColorAttributeName]=[UIColor orangeColor];
    [vc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    YJNavigationController *nav=[[YJNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}

  

 

使用方法:

 YJMeViewController *me=[[YJMeViewController alloc] init];
    [self createChildVcWithVc:me Title:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM