UITabbar in Xcode 6 - ios

I have UITabbarController with 4 tabs in iPhone 4, 4s, 5, 5S it is woking fine with tabbar item image
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
And, iPhone 6 Plus

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!

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.

Related

iPhone Plus: why is UISplitViewController showing both controllers in landscape?

I am using a UISplitViewController with these values:
splitViewController.preferredPrimaryColumnWidthFraction = 0.4
splitViewController.minimumPrimaryColumnWidth = 320
splitViewController.maximumPrimaryColumnWidth = 1000
On iPhone 6 in landscape, the UIViewController shows just 1 controller
On iPhone 6 Plus in landscape, the UIViewController shows both controllers
I can't understand why.
Given the screen sizes of both devices:
iPhone 6: 375 x 667
iPhone 6 Plus: 414 x 736
736 x 0.4 = 294.4, which is still smaller than 320
why it's then showing both controllers in landscape for iPhone Plus?
UPDATE:
It looks like preferredPrimaryColumnWidthFraction and minimumPrimaryColumnWidth have nothing to do with the threshold width that causes the split. They just define the width of the first controller, in case both controllers are shown.
I am now looking for a way to prevent the split on the iPhone Plus, so that it behaves the same as the iPhone non-Plus.
Please check that. Require Full Screen. below Status Bar Style.
Another way:
first check your current mode on different devices.
- (void)splitViewController:(UISplitViewController *)splitViewController willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode {
if (displayMode == UISplitViewControllerDisplayModePrimaryHidden) {
NSLog(#"Detail view is visible");
} else if (displayMode == UISplitViewControllerDisplayModeAllVisible) {
NSLog(#"both are visible");
}
}
then set your require preferredMode.

iOS background image for iphone 6

I'm trying to set a UIImage as the background of a UIView. The problem is that if I use colorWithPatternImage the background image repeats for the iPhone 6 (as far as I know it uses de #2x resolution).
For the iPhone 6 plus I have no problems because it uses de #3x image but iPhone 4,4s,5,5s and 6 uses the same 2#x image and have differents screen sizes.
I'm using Xcode 6.
I have the same problem and I solved following this post
Basically you can use:
a single image set for 1x, 2x and R4. This covers iPhone 4, 4S and 5/5S/5C – as well as iPads scaling the app up from iPhone 4 layout
an “xxxxx-oversize” image set for iPhone 6
an “xxxxx-overize#3x” set for iPhone 6 Plus
After than use a custom category on UIImage to load from the correct asset based on display size
#import "UIImage+ImageAdditions.h"
#implementation UIImage (ImageAdditions)
+ (NSString *)resolveAdaptiveImageName:(NSString *)nameStem {
CGFloat height = [UIScreen mainScreen].bounds.size.height;
if (height > 568.0f) {
// Oversize #2x will be used for iPhone 6, #3x for iPhone 6+
// iPads... we'll work that out later
if (height > 667.0f) {
return [nameStem stringByAppendingString:#"-oversize#3x"];
} else {
return [nameStem stringByAppendingString:#"-oversize"];
}
};
return nameStem;
}
+ (UIImage *)adaptiveImageNamed:(NSString *)name {
return [self imageNamed:[self resolveAdaptiveImageName:name]];
}
#end

Auto Layout iphone 4 - 6plus

Since apple has now introduced the iPhone 6 + 6 plus. How would I make the image for different sizes of phones? For iPhone 4 and 5/5s/5c you would do
#define IS_568_SCREEN (fabs((double) [[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSLION)
if(IS_568_SCREEN) {
//Iphone 5/5s/5c
} else {
//iphone 4s }
But how would you do it for iPhone 4s to iPhone 6 plus? Also my auto layout isn't working very well. Im trying to change the size for all my objects dependent of the phone and using auto layout to place them correctly. However its not working out, I'm doing "height", "leading space to Container Margin", "Bottom Space To Bottom layout" and "Trailing space to container". As this will be a little hard and time consuming for all the objects sizes, can I use multiple storyboards? and what I mean by that is can I have one storyboard file for iPhone 6, then one for iPhone 6 plus etc. Or if not whats the proper way of doing auto layout on the interface builder?
Here's the answer to what I was looking for, nothing complicated :)
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = screenRect.size.height;
if (screenHeight == 480) {
// do iPhone 4s stuff
} else if (screenHeight == 568) {
// do iPhone 5, 5s, 5c stuff
} else if (screenHeight == 667) {
// do iPhone 6 stuff
} else if (screenHeight == 736) {
//do iPhone 6 plus stuff
}

xcode 6 is iphone 5 no longer 568 points in height?

So I'm trying to update my game to fit the iPhone 6 properly and i see now that when i run my game on the iPhone 5 simulator, everything is fitting as if it were an iPhone 4. I use if statements to determine the height of the device:
if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
mylabel4.fontSize = 35;
mylabel4.position = CGPointMake(CGRectGetMidX(self.frame) -145, CGRectGetMidY(self.frame) -130);
} else {
mylabel4.fontSize = 35;
mylabel4.position = CGPointMake(CGRectGetMidX(self.frame) -110, CGRectGetMidY(self.frame) - 130);
}
And like i said when i run the iPhone 5 simulator, it runs the code in the 'else' bracket. Its like the iPhone 5 is no longer 568 points in height. This was working fine until i download Xcode 6? What's going on here?
The UIScreen bounds behavior has changed in iOS8. Previously it would always give you width and height of the screen in portrait (so 320 x 568 on the iPhone 5), but in iOS8 it will give you width and height with respect to whatever orientation you're in, i.e. in landscape you would get 568 x 320.
If you want to get the bounds in portrait (like before), use:
[UIScreen mainScreen].fixedCoordinateSpace.bounds.size
Just add launch images for the iPhone and the simulator will display the proper points. Weird bug.

Xcode 4.5 background image iPhone 4, 4s, 5

I have in my viewController.m written the background code:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"image.png"]];
And I have the correct names of the different pictures:
image.png for non-retina display (320x480)
image#2x.png for retina display (640x960)
image-568h#2x.png for iPhone 5 (640x1136)
But when I run it in the simulator it does not take the image-568h#2x.png for iPhone 5 screen it only takes the image#2x for 4s screen and scale it to fit the screen... I dont know if there is any coding to use the image-568h#2x for iPhone 5 screen?
Im using Xcode 4.5
iPhone 5 is retina, just like iPhone 4 and 4S, and the #2x-image will be used automatically for all these devices. It's only the startup-image that is called "-568h#2x" for iPhone 5. You need to write some code to use a different image, something like this would work:
NSString *filename = #"image.png";
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
filename = [filename stringByReplacingOccurrencesOfString:#".png" withString:#"-568h.png"];
imageView.image = [UIImage imageNamed:filename];
if you are trying to use [UIImage imageNamed:#"image.png"] and expect image-568h#2x.png to be picked automatically from the bundle for iPhone 5, it will not work.
Automatic picking works only for iPhone 4 and 4S.
Only the Default image named as Default-568h#2x.png will be picked automatically in iPhone 5.
for normal images, if you have separate image for iPhone 5, try using this code
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
} else {
// code for 3.5-inch screen
}
I believe it is incorrect to assume that you can apply the -568h#2x trick to all image files. I think it only works for Default-568h#2x.png. This is the file that iOS looks for at app launch on a 4" display device, as well as the "flag" to enable 4" display support in the SDK. For example, once you include this specific file, your table views will fill the screen.
I have not read anything to suggest that you can simply provide any image with the -568h#2x file name component and have it be used automagically. You'll have to do that yourself based on the screen size, e.g. [UIScreen mainScreen].bounds.size.height.

Resources