自定义tabbar 显示图片

首先在appdelegate

导入

#import "WatchTabBarViewController.h"

#import "WatchTabBarItem.h"


然后设置根视图中  调用 

- (void)customizeInterface {

    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];

    

    UIImage *backgroundImage = nil;

    NSDictionary *textAttributes = nil;

    

    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {

        backgroundImage = [UIImage imageNamed:@"navigationbar_background_tall"];

        

        textAttributes = @{

                           NSFontAttributeName: [UIFont boldSystemFontOfSize:18],

                           NSForegroundColorAttributeName: [UIColor blackColor],

                           };

    } else {

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0

        backgroundImage = [UIImage imageNamed:@"navigationbar_background"];

        

        textAttributes = @{

                           UITextAttributeFont: [UIFont boldSystemFontOfSize:18],

                           UITextAttributeTextColor: [UIColor blackColor],

                           UITextAttributeTextShadowColor: [UIColor clearColor],

                           UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],

                           };

#endif

    }

    

    [navigationBarAppearance setBackgroundImage:backgroundImage

                                  forBarMetrics:UIBarMetricsDefault];

    [navigationBarAppearance setTitleTextAttributes:textAttributes];

}


在调用

- (void)setupViewControllers {

     UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

    UIViewController *firstViewController = [storyBoard instantiateViewControllerWithIdentifier:@"homeController"];

    UIViewController *firstNavigationController = [[UINavigationController alloc]

                                                   initWithRootViewController:firstViewController];

    

    UIViewController *secondViewController = [[WatchFunCtionVC alloc] init];

    UIViewController *secondNavigationController = [[UINavigationController alloc]

                                                    initWithRootViewController:secondViewController];

    

   

//    UIViewController *thirdViewController = [storyBoard instantiateViewControllerWithIdentifier:@"homeController"];

    MineController *thirdViewController = [[MineController alloc]init];

        UIViewController *thirdNavigationController = [[UINavigationController alloc]

                                                       initWithRootViewController:thirdViewController];

    

    WatchTabBarViewController *tabBarController = [[WatchTabBarViewController alloc] init];

    [tabBarController setViewControllers:@[firstNavigationController,secondNavigationController,thirdNavigationController]];

    self.viewController = tabBarController;

    

    [self customizeTabBarForController:tabBarController];

}

指定显示的图片  

- (void)customizeTabBarForController:(WatchTabBarViewController *)tabBarController {

//    UIImage *finishedImage = [UIImage imageNamed:@""];

//    UIImage *unfinishedImage = [UIImage imageNamed:@""];

//    NSArray *tabBarItemImages = @[@"", @"", @""];

//    

//    NSInteger index = 0;

//    for (WatchTabBarItem *item in [[tabBarController tabBar] items]) {

//        [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];

//                UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",

//                                                              [tabBarItemImages objectAtIndex:index]]];

//                UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",

//                                                                [tabBarItemImages objectAtIndex:index]]];

//        

//        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];

//        

//        index++;

//    }

}


设置tabbar的隐藏 需要调用的方法

 [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值