简体   繁体   中英

How to set TabBar Image in UITabBarController

I have used UITabBarController in my application.

I am really confuse about what image size should be there for UITabBar . It must support all devices. iPhone 4s,5,5s,5c,6,6 plus .

Sometimes it's create space between tabs. If I change image size then sometimes it looks blur.

I have put normal image, @2x and also @3x .

@3x - 312*180

@2x - 160*120

normal - 80*56

So as per my understanding iPhone 6 should take @2x image but it's not taking it. There is space between tabs in iPhone 6. So I programmatically set images for iPhone 6 and give it's size as 93*56 . Then spaces between tabs has been removed and set properly. But now what problem I am facing. Images looks blur in iPhone 6. Don't know what to do now.

Can anybody please help me out here? How can I manage images of tabs which supports all devices. Thanks in advance!

在此处输入图片说明 Here is my code,

- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
    // Override point for customization after application launch.

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

    UITabBarController *tabController = [[UITabBarController alloc]init];

    UINavigationController *navController1 = [[UINavigationController alloc]initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"ViewController1"]];

    UINavigationController *navController2 = [[UINavigationController alloc]initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"ViewController2"]];

    UINavigationController *navController3 = [[UINavigationController alloc]initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"ViewController3"]];

    UINavigationController *navController4 = [[UINavigationController alloc]initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"ViewController4"]];

    tabController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, navController3, navController4, nil];


    [[[tabController.viewControllers objectAtIndex:0] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"chords-active1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"chords1.png"]];

    [[[tabController.viewControllers objectAtIndex:2] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"progression-active1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"progression1.png"]];

    [[[tabController.viewControllers objectAtIndex:1] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"practice-selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"practice.png"]];

    [[[tabController.viewControllers objectAtIndex:3] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"settings-active1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"settings1.png"]];

    self.window.rootViewController = tabController;

    return YES;
}

Follow this IconMatrix Guide provided by Apple. You will get everything..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM