ios tabbar背景图片设置

 

[tabBarC.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];

 

 

- (id)init

{

    self = [super init];

    if (self) {

        // Custom initialization

        self.tabBar.barStyle = UIBarStyleDefault;

        self.tabBar.backgroundColor = [UIColorcolorWithHexString:@"#FFFFFF"alpha:1.0f];

        self.tabBar.translucent = NO;

    }

    returnself;

}

 

+ (instancetype)tabBarC

{

    SJBTabBarController *tabBarC = [[SJBTabBarControlleralloc] init];

    

    HomeViewController *firstVC = [[HomeViewControlleralloc]initWithNibName:@"HomeViewController"bundle:nil];

    RecommentViewController *secondVC = [[RecommentViewControlleralloc]initWithNibName:@"RecommentViewController"bundle:nil];

    secondVC.isTabBarVC = YES;///额外添加的。

    SJBMyCollectViewController *thirdVC = [[SJBMyCollectViewControlleralloc]init];

    

    UINavigationController *naviFirstVC = [[UINavigationControlleralloc]initWithRootViewController:firstVC];

    naviFirstVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"全球地铁" image:[UIImageimageNamed:@"tab_home_normal"] selectedImage:[UIImage imageNamed:@"tab_home_select"]];

    naviFirstVC.tabBarItem.tag = 0;

    UINavigationController *naviSecondVC = [[UINavigationControlleralloc]initWithRootViewController:secondVC];

    naviSecondVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"世界旅行" image:[UIImageimageNamed:@"tab_travel_normal"] selectedImage:kImageNamed(@"tab_travel_select")];

    naviSecondVC.tabBarItem.tag = 1;

    UINavigationController *naviThirdVC = [[UINavigationControlleralloc]initWithRootViewController:thirdVC];

    naviThirdVC.tabBarItem = [[UITabBarItemalloc] initWithTitle:@"我的收藏" image:[UIImageimageNamed:@"tab_collect_normal"] selectedImage:[UIImage imageNamed:@"tab_collect_select"]];

    

    naviThirdVC.tabBarItem.tag = 2;

    tabBarC.tabBar.clipsToBounds = YES;

    

    [tabBarC setViewControllers:[NSMutableArray arrayWithObjects:naviFirstVC, naviSecondVC, naviThirdVC, nil]];

    [tabBarC.tabBar setBackgroundImage:kImageNamed(@"tab_left_press")];

    [tabBarC.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];

    return tabBarC;

}

 

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

{

    UINavigationController *navC = (UINavigationController *)viewController;

    if ([navC.topViewController isKindOfClass:[HomeViewController class]]){

        [tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_left_press")];

    }elseif ([navC.topViewControllerisKindOfClass:[RecommentViewControllerclass]]){

        [tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_middle_press")];

    }else{

        [tabBarController.tabBar setBackgroundImage:kImageNamed(@"tab_right_press")];

    }

      returnYES;

 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值