UITabbar in Xcode 6

2019-05-25 00:01发布

I have UITabbarController with 4 tabs in iPhone 4, 4s, 5, 5S it is woking fine with tabbar item image

enter image description here

But in iPhone 6 and iPhone 6 plus is looking wired. Is it need to put different images for both iPhone 6 and iPhone 6 plus ? How can I set this images.

in iphone 6

enter image description here

And, iPhone 6 Plus

enter image description here

2条回答
对你真心纯属浪费
2楼-- · 2019-05-25 00:03

You need to make new size for iPhone 6 and iPhone 6 Plus.

Indeed they have new resolution: iPhone 6 (1334-by-750-pixel) and the iPhone 6 Plus (1920-by-1080-pixel).

Moreover if you are using auto-Layout you need to update your constraints.

查看更多
你好瞎i
3楼-- · 2019-05-25 00:21

I ran into this same issue. The problem here is not only the different resolution, but the fact that the size of the bounds is actually wider for iphone 6 and iphone 6 plus. By running the simulator on all different phone types I found the following:

Tab bar Bounds
iPhone 6 plus:  414 x 49
iPhone 6:       375 x 49
iPhone 5:       320 x 49
iPhone 4        320 x 49

This means that you must use different background images for iphone 6 and 6 plus. I'm not sure if this is the most efficient way to do this, but it fixed it for me:

UITabBarController *tabBarController = (UITabBarController *) self.parentViewController;
UITabBar *tabBar = tabBarController.tabBar;

if ([[UIScreen mainScreen] bounds].size.height > 700) {
    tabBar.selectionIndicatorImage = [UIImage imageNamed:@"tabbar-selected6Plus"];
} else if ([[UIScreen mainScreen] bounds].size.height > 600) {
    tabBar.selectionIndicatorImage = [UIImage imageNamed:@"tabbar-selected6"];
} else {
    tabBar.selectionIndicatorImage = [UIImage imageNamed:@"tabbar-selected"];
}

Hope that helps!

查看更多
登录 后发表回答