如何在UITabBarController中设置TabBar图像

时间:2015-04-29 06:21:12

标签: ios objective-c ios8 uitabbarcontroller uitabbar

我在我的应用程序中使用了UITabBarController

我真的很担心image size UITabBar应该是什么。它必须支持所有设备。 iPhone 4s,5,5s,5c,6,6 plus

有时它会在标签之间创建空间。如果我更改image size,则有时会看起来很模糊。

我已放置普通图片,@2x以及@3x

@3x - 312*180

@2x - 160*120

normal - 80*56

根据我的理解,iPhone 6应该采用@2x图像,但它没有接受它。 iPhone 6中的标签之间有空格。因此,我以编程方式为iPhone 6设置图像,并将其大小设置为93*56。然后删除并正确设置选项卡之间的空格。但现在我面临的问题是什么。 iPhone 6中的图像看起来很模糊。不知道现在该做什么。

有人可以帮帮我吗?如何管理支持所有设备的选项卡图像。 提前谢谢!

enter image description here 这是我的代码,

- (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;
}

2 个答案:

答案 0 :(得分:2)

按照Apple提供的IconMatrix Guide进行操作。你会得到一切......

答案 1 :(得分:1)