This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to develop or migrate apps for iPhone 5 screen resolution?
As I attached an Image, I've generated view in XIB for iPhone-5 screen size. When I'll run as iPhone-4s retina for iPhone5 screen, but It'll show like this in the simulator for the iPhone-4s screen.
I've done with all size settings auto with screen size attributes.
Actually Not getting to the status-bar issue.
If the screen is not compatible with large screen, then also status-bar should be on top. But why is it so showing in the middle ?
Can anyone tell me the solution for this asap?
Thanks in advance.
You can add the splash Image to your project named Default-568h#2x.png
This will show your layout in full screen rather than displaying it in middle.
Set this in App delegate class in Didfinishlaunching method:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
I have been successful in this earlier.
Write [[UIApplication sharedApplication] setStatusBarHidden:NO]; in AppDelegate and in .plist file set property Statusbar is initially hidden to YES.
Hope this will help you....:)
You can check device screen compatibility as below:
//Device Compatibility
#define g_IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"] )
#define g_IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPod touch"] )
#define g_IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPad"] )
#define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
if(g_IS_IPHONE_5_SCREEN)
{
if(g_IS_IPHONE)
NSLog(#"Hey, this is an iPhone 5 screen!");
else if(g_IS_IPOD)
NSLog(#"Hey, this is an iPod 5 screen!");
else
NSLog(#"Hey, this is a simulator screen with iPhone 5 screen height!");
}
else if(g_IS_IPHONE_4_SCREEN)
{
if(g_IS_IPHONE)
NSLog(#"Hey, this is a lower iPhone screen than 5!");
else if(g_IS_IPOD)
NSLog(#"Hey, this is a lower iPod screen than 5!");
else
NSLog(#"Hey, this is a lower simulator screen than 5!");
}
else if(g_IS_IPAD){
NSLog(#"Hey, this is an iPad screen!");
}
else{
NSLog(#"Hey, this is an ipad simulator screen!");
}
Cheers!
Related
I have an application that I am making with A UIDatePicker and a UIToolBar attached to a view. The UIToolBar has an animation set to slide up. this is where my problem is. On the iPhone 4 the toolbar needs to finish its animation at a lower position than on the iPhone 5. How do I set the height differently for each device?
You can distinguish iPhone 5 from iPhone 4 like this:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0){
//is iPhone 5
}
else{
//is iPhone 4
}
Then, set your UIToolBar's frame appropriately for each screen size.
Also, here's the macro for convenience (put this in your .pch file):
#define IS_4_INCH_SCREEN [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0
you should get the screen size first and then use if condition, if the screensize is corresponding the iphone 5 screen and then place accordingly
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
// for iphone 5
}
else
{
// assume that another option is iphone 4 only,
}
How do I make the UIImageView fit the Retina 4-inch display? Thanks.
If you are developing your app for iOS 6 then use Autolayouts for this.
Else you can use AutoResizing feature if managing height through NIB.
If you want to manage it programmatically you can use this code :
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
then set frame as :
[your_imageview setFrame:CGRectMake(0.0f, 0.0f, 320.0f, IS_IPHONE_5?568.0f:480.0f)];
Hope it helps you.
The common practice I followed earlier during creating XIB files for universal applications was as follows:
I create the Xib file for both iPhone and iPad. Name them as XibFile.xib and XibFile~ipad.xib. For iPhone 4/4s and iPad3 I used retina images, where ever required. So that covered all my UI designs. And also my clients needed the iPhone5 screens in letterbox mode. I did not use the Default-568h#2x.png. So life was going smooth at my end.
But now when Apple decided to stop supporting Letterbox mode since May 1(read this article), I needed Xib level changes for iphone5 screens also. So for now I used auto resizing in the Xib file, and used vertical expansion for all my screens, and that solved most of my issues.
Now please advice me the best practice in doing the XIB file creation, providing support to iphone5/4/4s and iPad.
1.) Design for iphone5, 4" screens and use auto resizing for iPhone 4/4s. This will not compromise in the clarity of the images I use.
2.) Create 2 different Xib files for iphone. One for the 4" iPhone5 and other for normal iPhone4/4s screens.
Please advice which is the best practice. Also please let me know, if there is some other way.
You only need to create multiple XIBs if the lay out is fundamentally different for the different devices.
If you can reuse the same XIB for both iPhone 4 and 5 with appropraite autoresizing behaviour, do so.
Best way would be to check for different models of iphone or ipad and do the needful accordingly. You can check iphone versions using the below code.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: #selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960) {
NSLog(#"iPhone 4 Resolution");
resolution_number = 1;
}
if(result.height == 1136) {
NSLog(#"iPhone 5 Resolution");
}
}
else{
NSLog(#"Standard Resolution");
}
}
Using auto resizing is a good solution, it keeps your interface definitions and code simple and minimal. There would probably be very few differences between the 4 & 5 XIB files.
The area you're likely to see issues using this method is where you have scroll views defined in the XIB where the content size is specified only in the XIB. In this case you'll need to add a bit of code to calculate the content size and possibly resize the content as autoresizing won't cover it.
Take different xib and put this coding you can easily manage.
//Device Compatibility
#define g_IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"] )
#define g_IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPod touch"] )
#define g_IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPad"] )
#define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
if(g_IS_IPHONE_5_SCREEN)
{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
}
else if(g_IS_IPHONE_4_SCREEN)
{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:#"DashboardViewController4" bundle:nil];
}
else if(g_IS_IPAD){
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:#"DashboardViewControllerIpad" bundle:nil];
}
else{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:#"DashboardViewController" bundle:nil];
}
you can easily put your condition
I am new to iPhone development i want to make my code compatible with iPhone 4s and iPhone5
but when i apply image to background view of 4S its size 320*480 but it changes in iPhone 5.
How to manage this compatibility?
Also do i need manage compatibility for buttons and their position in iPhone 4s and iPhone 5.
If yes? then how to handle position of button pro-grammatically...
I found this solution ..
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic }
if(result.height == 568)
{
// iPhone 5
}}
Does it works?
Yes, you are doing it in correct way.
Now, what you need to do is, you just need check the condition and based on that, you have to set the Frame of the components on the screen.
if([UIScreen mainScreen].bounds.size.height == 568)
{
// iPhone 5
// Set the frame of the buttons for iPhone5 screen
}
else
{
// iPhone 4
// Set the frame of the buttons for iPhone4 & 4S screen
}
}
I am making an iphone app at the moment. But in the future this app should also be available for iPad. At the moment I am using storyboards, because it's quite easy to make it also available for iPad in this way.
My question is now, some views like a long profile form, you put it inside a scrollview. But you cannot build scrollviews layouts inside a storyboard, so I created them in code. But what should I do if I want this views layout also available for iPad?
Should I rewrite the layout code for iPad and then do some device detection?
What is the best practice?
I think better detect hardware and write different layout code.
You can use Apple's Macro:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Write your layout code for iPad there
}
else
{
// Write your layout code for iPhone/iPod there
}
Below will be useful for you.
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"] )
#define IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPod touch"] )
#define IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:#"iPad"] )
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
if(IS_IPHONE_5_SCREEN)
{
if(IS_IPHONE)
NSLog(#"Hey, this is an iPhone 5 screen!");
else if(IS_IPOD)
NSLog(#"Hey, this is an iPod 5 screen!");
else
NSLog(#"Hey, this is a simulator screen with iPhone 5 screen height!");
}
else if(IS_IPHONE_4_SCREEN)
{
if(IS_IPHONE)
NSLog(#"Hey, this is a lower iPhone screen than 5!");
else if(IS_IPOD)
NSLog(#"Hey, this is a lower iPod screen than 5!");
else
NSLog(#"Hey, this is a lower simulator screen than 5!");
}
else if(IS_IPAD){
NSLog(#"Hey, this is an iPad screen!");
}
else{
NSLog(#"Hey, this is an ipad simulator screen!");
}
Cheers!
The solution was rather simple.
First I thought you cannot create scrollviews inside a storyboard. But this is possible!
You can find how to do it over here.
So now the solution is that you create another storyboard specifically for iPad!