Launch image choose longer - ios

I have a universial app .I added Launch images to project .
I want to wait splash screen until download json from webservice. my app it's waiting until download json. but launch image choosing is not correct or position.I wrote this following code.for example: my launch image correct on iphone 5 . but not on iphone 3gs.
How can I do that easily? sorry my English . Thank you.
CGRect screenRect = [[UIScreen mainScreen] bounds];
float screenWidth = screenRect.size.width;
float screenHeight = screenRect.size.height;
splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
NSLog(#"height %f version %f",[[UIScreen mainScreen] bounds].size.height,sysVer);
if (sysVer <7.0)
{
// iOS-6.01 and prior code
if (screenHeight==480)
{
splashView.image=[UIImage imageNamed:#"Default"];//iPhone
}
else if (screenHeight == 568.0f)
{
splashView.image=[UIImage imageNamed:#"Default-568h#2x.png"];
}
}
else // for ios7
{
if (!screenHeight == 568.0f)
{
splashView.image=[UIImage imageNamed:#"Default"];//iPhone
}
else
{
splashView.image=[UIImage imageNamed:#"Default-568h#2x.png"];
}
}
}
else
{
if (sysVer <=6.1)
{
splashView.image=[UIImage imageNamed:#"Default-Portrait"];// iPads
}
else
{
splashView.image=[UIImage imageNamed:#"Default-7681024"];// iPads
}
}
[self.view addSubview:splashView];
log is on iphone 3gs
height 480.000000 version 6.100000

Related

Change status bar height, based on if the device is an iPhone X or not

In my application, I use a custom pod called MMDrawerController, to create a dummy status bar, unfortunately in the pod the status bar's height is always set to 20.
In order to fix this issue I have written the following code:
App delegate
MMDrawerController *mmdrawer = [[MMDrawerController alloc]init];
//UPDATE IPHONE X STATUS BAR
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.height == 812.0f) {
NSLog(#"DEVICE NAME : iPhone X");
self.iphoneXHeight = -45.0;
self.iphoneXHeightPos = 45.0;
mmdrawer.height = 40;
}
else {
self.iphoneXHeight = -20.0;
self.iphoneXHeightPos = 20.0;
mmdrawer.height = 20;
}
}
MMDrawerController.h
#property (nonatomic,assign) CGFloat height;
MMDrawerController.m
_dummyStatusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), self.height)];
Problem:
When I run my code the height property is always 0, would appreciate it if someone can point out what I am doing wrong here and how would I be able access the height property and modify it ?
Dont use fixed height for the status bar, you can get the height with this code:
UIApplication.sharedApplication.statusBarFrame.size.height
Change this line.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.height == 812.0f) {
NSLog(#"DEVICE NAME : iPhone X");
self.iphoneXHeight = -45.0;
self.iphoneXHeightPos = 45.0;
mmdrawer.height = 40;
}
With this one:
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
// determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;
switch (screenHeight) {
// iPhone 5s
case 568:
NSLog(#"iPhone 5 or 5S or 5C");
break;
// iPhone 6
case 667:
NSLog(#"iPhone 6/6S/7/8");
break;
// iPhone 6 Plus
case 736:
NSLog(#"iPhone 6+/6S+/7+/8+");
break;
// iPhone X
case 814:
NSLog(#"iPhone X");
break;
default:
// it's an iPad
printf("unknown");
}
}

alignment for different ios device

I am new to iOS programming. I made an application for iPhone retina 4-inch. Now I want to customise my code in order for it to run on an iPhone retina-3.5 inch and iPhone 5.
I tried to create an if query for self.view.frame.size.width and self.view.frame.size.height, but I get a "Not assignable" error.
Can anyone tell me how to specify conditions for setting up the workspace nicely in all devices? If possible please give me the exact screen-size of all that devices.
You can use this:
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
References:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIScreen_Class/Reference/UIScreen.html
You look at the device's screen size (in points) and from that surmise if it's an iPad or iPhone etc., and then use hard-coded values for the screen sizes.
Here's some code to get the screen size:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
Be aware that width and height might be swapped, depending on device orientation.
to compare screen size include this macro and use it any where necessary
#define isPhone5 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
if you want to compare screen sizes only then reduce the above macro to
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
For example in your .m file
#import "ViewController.h"
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE //hear u put the macro and use it anywhere in this file
#interface ViewController ()<FootballPlayerDelegate>//confirms to this delegate
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if(isiPhone5)
{
NSLog(#"I am 4inch screen");
}
else
{
NSLog(#"I am 3.5inch screen");
}
// Do any additional setup after loading the view, typically from a nib.
}
Try this In your .M file:
-(void)viewWillAppear:(BOOL)animated
{
[self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:1.0];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft)
{
[self setFrameForLeftAndRightOrientation];
}
else if(orientation == UIInterfaceOrientationPortrait )
{
[self setFrameForPortraitAndUpsideDownOrientation];
}
}
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self setFrameForLeftAndRightOrientation];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
[self setFrameForPortraitAndUpsideDownOrientation];
}
}
-(void)setFrameForLeftAndRightOrientation
{
if(IS_IPAD)
{
//Write here code for iPad (Landscape mode)
}
else if(IS_IPHONE)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
//Write code here for iPhone 5 (Landscape mode)
}
else
{
//Write code here for iPhone(3.5 inch) (Landscape mode)
}
}
}
-(void)setFrameForPortraitAndUpsideDownOrientation
{
if(IS_IPAD)
{
}
else if(IS_IPHONE)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
}
}
}
#define IS_IPHONE_SIMULATOR ([[[UIDevice currentDevice]model] isEqualToString : #"iPhone Simulator"])
#define IS_IPHONE ([[[UIDevice currentDevice]model] isEqualToString : #"iPhone"])
#define IS_IPOD_TOUCH ([[[UIDevice currentDevice]model] isEqualToString : #"iPod Touch"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define ITS_IPHONE5 ( IS_HEIGHT_GTE_568 )
if (ITS_IPHONE5)
{
}
else
{
}
Use This Code in project-Prefix.pch file in supporting file folder.
#define IS_IPHONE_SIMULATOR ([[[UIDevice currentDevice]model]
isEqualToString : #"iPhone Simulator"])
#define IS_IPHONE ([[[UIDevice currentDevice]model] isEqualToString : #"iPhone"])
#define IS_IPOD_TOUCH ([[[UIDevice currentDevice]model] isEqualToString : #"iPod Touch"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define ITS_IPHONE5 ( IS_HEIGHT_GTE_568 )
Copy and Past This Code After That in your .m File past the first code i give you...
Dont need to write size on viewdidload write only in these cots
if (IS_IPAD)
{
}
else if(IS_IPHONE)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
}
}

Find device type iPhone 4 or iPhone5 not working [duplicate]

This question already has answers here:
How to detect iPhone 5 (widescreen devices)?
(24 answers)
Closed 9 years ago.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
//NSLog(#"phonesize%#",result);
if(result.height > 500){
NSLog(#"iPhone 5");
}
else{
NSLog(#"iPhone 4");
}
}
My Mac OS is 10.7.2 and Xcode 4.5.2.I used above code to find device is iPhone 4 or iPhone 5
It is giving iPhone4 when i uses iPhone5.I did set launch image and icon image. Is there anything else i missed out?
Make sure you have a PNG file named Default-568h#2x.png in your project.
You need to scale the result you got as per the screen's scale scale and then check ...
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");
}
if(result.height == 1136) {
NSLog(#"iPhone 5");
}
}
else{
NSLog(#"Standard Resolution");
}
}
Try this code instead its tested.
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
{
//device is iPhone
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
//device is iphone 5
//add storyboard/Xib that have large screen (320*568)
} else {
//device is iphone 4
//add story board/Xib that have small screen (320*480)
}
}
else
{
//device is iPad
}
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
//iphone 5
else
{
//iphone 4
}
}
else
{
//iPad
}
Try this one might be helpful to you...

Button with different width on iPhone 5

I want to increase the size of a custom button if the user is using an iPhone 5.
This is what I have in my .m file
//.m File
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
int varWidth = 228;
}
if(result.height == 568)
{
int varWidth = 272;
}
}
....
[newButton setFrame:CGRectMake(8.0, 40.0, 228, 80.0)];
But I want something like this:
[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
You are using varWidth out of it's scope.
int varWidth;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
varWidth = 228;
}
if(result.height == 568)
{
varWidth = 272;
}
}
....
[newButton setFrame:CGRectMake(8.0, 40.0, varWidth, 80.0)];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[newButton setFrame:CGRectMake(8.0, 40.0, 228.0, 80.0)];
}
if(result.height == 568)
{
[newButton setFrame:CGRectMake(8.0, 40.0, 272, 80.0)];
}
}
Why not do this way?
Another suggestion:
Use #define.
For example:
#define iPhone5width 272
#define iPhone4width 228
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[newButton setFrame:CGRectMake(8.0, 40.0, iPhone4width, 80.0)];
}
if(result.height == 568)
{
[newButton setFrame:CGRectMake(8.0, 40.0, iPhone5width, 80.0)];
}
}
The Best and Short way, For check device is iPhone 5 or iPhone5 < (Less Then).
For get this you need to write following code in your .pch file of project.
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
This Like check device, is it iPhone5 or not.
And you need to write only one condition for manage it
if( IS_IPHONE_5 )
// set or put code related to iPhone 5.
else
// set or put code related to less then iPhone 5.

coding for iphone 5 screen

I have taken a universal project. I have coded for iPhone 5 screen but it doesn't detect it.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//ui for ipad
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
tableView.frame = CGRectMake(0, 40, 320 ,508);
}
else {
tableView.frame = CGRectMake(0, 40, 320 ,420);
}
}
It doesn't work though. When I debug the code on iPhone 5 screenBounds = 320*480.
Where am I going wrong?
It is so simple to detect iPhone5 screen,
Just write
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
in your .pch file.... and you can further check for iPhone5 screen like if(IS_IPHONE5).
Choose your UITableView from the IB and select the size as Retina 4 for all screens, even the main window xib file. This works fine even on the iphone 4.
you add Splash Screen for iphone 5.Default-568h#2x.png file then its work fine
This code works fine for me
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
if (IS_IPHONE_5)
   {
//iphone 5
}
Try using this to detect iPhone 5 instead:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize theHeight = [[UIScreen mainScreen] bounds].size;
if(theHeight.height == 568) {
// iPhone 5
tableView.frame = CGRectMake(0, 40, 320 ,508);
}
else {
// iPhone 4
tableView.frame = CGRectMake(0, 40, 320 ,420);
}
}
Alternatively you can define this:
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
Which you can re-use whenever you need to find out if it's iPhone 5 or not.
Try this code ::
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[tableView setFrame:CGRectMake(0, 40, 320 ,508)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[tableView setFrame:CGRectMake(0, 40, 320 ,420)];
}
Hope, it'll help you.
Thanks.
I used this code to check iPhone 5 device.
float scrnheight = [[UIScreen mainScreen] bounds].size.height ;
if(scrnheight == 568.0f)
{
self.isIphone5 = true;
}

Resources