iPhone simulator does not show iphone 5 compatible image - iphone

I have long across many questions and answer regarding element settings for old and new iphone screens and got some idea as well. I have a query...I am preparing an app for iphone 320X480(iPhone), iphone retina 3.5 inch and 4 inch retina screens. For an instance of window (background) which I want to set programatically. It has to with a titlebar. so what I have done so far checked the screen size with
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f) {
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Do-568h#2x.png"]];
[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];
} else {
UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Do.png"]];
[self.view addSubview:backgroundImage];
[self.view sendSubviewToBack:backgroundImage];
}
First block would check for iphone 5 screen (I presume) and second would set screen for normal and retina both screen for which I put 320X480 px image name Do.png and 640X960 image name Do#2x.png. The iphone and iphone 3.5 (Retina) displays well on simulator however iphone 4 (Retina) which I presume will be equal to iPhone 5 does not displays correctly. Please let me know what should i do...and yes Do-568h#2x.png is 640X1136....

use the below method to set the size of screen
- (void)iPhoneDeviceScreenSetting {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
lowerImgVw.frame = CGRectMake(0, 395, 318, 40);
}
if(result.height == 568)
{
// iPhone 5
lowerImgVw.frame = CGRectMake(0, 480, 318, 40);
}
}
}

Related

Display an App correctly on 3.5" and 4" screen

I almost finished to develop my App. Now I am trying to make it look nice in both iPhone 4 and 5.
I am trying to get the height of my scren but the following method doesn't work.
Any idea?
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
if (screenSize.height == 1136) {
NSLog(#"iphone 5");
}else if(screenSize.height == 960){
NSLog(#"iphone 4 retina");
}else{
NSLog(#"iphone 4 non retina");
}
this is the complete viewWillAppear method:
-(void)viewWillAppear:(BOOL)animated
{
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
NSLog(#"%#",NSStringFromCGSize(screenSize));
if (screenSize.height == 568.0f) {
NSLog(#"iphone 5");
}else if(screenSize.height == 480.0f){
NSLog(#"iphone 4 retina");
}else{
NSLog(#"iphone 4 non retina");
}
[firstStepsButton.titleLabel setHidden:YES];
[workingButton.titleLabel setHidden:YES];
[accommodationButton.titleLabel setHidden:YES];
[universityButton.titleLabel setHidden:YES];
[meetMeButton.titleLabel setHidden:YES];
[improveYourselfButton.titleLabel setHidden:YES];
self.navigationController.navigationBarHidden = TRUE;
// self.view.backgroundColor = [UIColor colorWithRed:2/255.0f green:42/255.0f blue:97/255.0f alpha:1.0f];
[super viewWillAppear:animated];
}
It wouldn't because the screen's coordinate system is in points, not pixels. Try it like this:
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
NSLog(#"%#",NSStringFromCGSize(screenSize));
if (screenSize.height == 568.0f) {
NSLog(#"iphone 5");
}else if(screenSize.height == 480.0f){
NSLog(#"iphone 4 retina");
}else{
NSLog(#"iphone 4 non retina");
}
You should also consider using UIDevice's userInterfaceIdiom to check whether the device is iPhone/iPad, and UIScreen's scale to determine whether the device is retina or not.
Consider downloading Xcode 5 DP where they fixed management of Autolayout in Interface Builder. It is now really easy to set and manage constraints. Try it out.

Imageview not display Proper For Iphone 5 Retina

I am developing one app in that app display 20 array Images to Image view Scroll horizontally.
give scroll view to that imageview like this
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
for (m = 0; m <=19; m++)
{
rnd = arc4random_uniform(arr.count);
NSString *imageName=[FrontsCards objectAtIndex:rnd];
fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=0;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[scrollView addSubview:ImgView];
}
this imageview not display images Properly for iphone 5 simulator. below black edge add.
how may i solve that issue.how to remove that black edge.how to fit that image to Iphone 5 simulator.
how may manage my ImageView to Iphone 4 or Iphone 5.
Iphone 5 size is 568 and Iphone 4 size is 480.
scrollView=[[UIScrollView alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
// For Iphone5
scrollView.frame = CGRectMake(0, 0, 320, 568)
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
//For Iphone 4 or others
scrollView.frame = CGCGRectMake(0, 0, 320, 480)
}
this will really helpful to you.
Iphone 5 screen size is 568 and you have had codded height to 480. So it is not working for iphone5.
DO following
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, [[UIScreen mainScreen] bounds].size.height)];
Depending on devise scroll view height will change.
Try This
scrollView=[[UIScrollView alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) scrollView.frame = CGRectMake(0, 0, 320, 568)
else if ([[UIScreen mainScreen] bounds].size.height == 480) scrollView.frame = CGRectMake(0, 0, 320, 480)
So, it will help you to fill scrollview in iPhone-5 screen too.
Hopefully, it'll work for you.
Thanks.
scrollView=[[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
use this to make the UIScrollView dynamic
Use macro to check whether it is iPhone 5 or not.
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:#"iPhone"] | [[[UIDevice currentDevice] model] isEqualToString:#"iPhone Simulator"])
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, IS_IPHONE_5?568:480)];
You need to create design for iPhone 4 and iPhone 5.
Create a class which make decision which iPhone is connected and
make function on it which accept CGRect and return required size of CGRect
you can get device size by
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height < 500)
{
currentDeviceHeight=460;
//You can use use iPhone 4 image
}
else
{
currentDeviceHeight=548;
// here you can use iPhone 5 image
}
}
else
{
// iPad
}

Overlapping UITextView border

I need to support Landscape and Portrait orientation for my app, and I venture into using a single UIView.
When I first simulate the application, it displays the result without a problem. However, when I change orientation to landscape, the problem occurs.
The first time I run the application in portrait:
When I change the orientation to landscape:
Notice the lower left corner, near the Information tab.
When I change back the orientation to portrait:
It gets worse.
The code I am using,
- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
CGFloat height = CGRectGetHeight([[UIScreen mainScreen] bounds]);
CGFloat width = CGRectGetWidth([[UIScreen mainScreen] bounds]);
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
NSLog(#"Portrait");
[self iPhoneUserInterfacePortrait:width height:height];
}
else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
NSLog(#"Landscape");
[self iPhoneUserInterfaceLandscape:width height:height];
}
}
- (void)iPhoneUserInterfacePortrait:(CGFloat)width height:(CGFloat)height
{
UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width - 100.0, height - 300.0)];
[self makeBorder:descriptionTextView];
[self setInformation:descriptionTextView];
[self.view addSubview:descriptionTextView];
}
- (void)iPhoneUserInterfaceLandscape:(CGFloat)width height:(CGFloat)height
{
UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width + 230, height - 368.0)];
[self makeBorder:descriptionTextView];
[self setInformation:descriptionTextView];
[self.view addSubview:descriptionTextView];
}
- (void)makeBorder:(UITextView *)descriptionTextView
{
descriptionTextView.layer.borderWidth = 3.0;
descriptionTextView.layer.cornerRadius = 15.0;
descriptionTextView.layer.borderColor = [[UIColor grayColor] CGColor];
[self.view addSubview:descriptionTextView];
}
You're adding several views while you want just one.
[self.view addSubview:descriptionTextView];
To get rid of this line, you could add field descriptionTextView to your ViewController subclass and change frame of that text view without adding/removing it from self.view.
Also you should try to play with AutoResizing masks to see if you can get needed results without actually changing frame manually.
And you should be careful with that constants: try your app on both 3.5 and 4.0 inch simulator devices.

Issues with migrating my app to iphone5 resolution

I am trying to migrate my app for iphone 5. I have already seen the other questions in stackoverflow and still facing the some problems in correctly showing it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,500)];
[_backgroundimageView setImage:[UIImage imageNamed:#"image1-568h#2x.png"]];
} else {
// code for 3.5-inch screen
[_backgroundimageView setImage:[UIImage imageNamed:#"image1.png"]];
}
The size I have set for backgroundimageView is 320 x370 in the size inspector and the image size of image1-568h#2x.png has a size of 640x 1136 and of image1.png is 640x733.So, for 3.5 inch screen, it should show normally and for 4-inch screen, it should resize accordingly.
But the problem is that for 4-inch screen, it doesn't resize and ends up showing me the same as 3inch screen with some white border to cover the remaining area.
Need some guidance to solve it. Thanks.. Can point out the mistake i am doing...
Why you are again allocating backgroundimageView for iPhone 5 resolutions. Just use the same IBOutlet of backgroundimageView and modify the frame and image of it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView.frame = CGRectMake(0,0,320,460);
[_backgroundimageView setImage:[UIImage imageNamed:#"image1-568h#2x.png"]];
} else {
// code for 3.5-inch screen
_backgroundimageView.frame =CGRectMake(0,0,320,370);
[_backgroundimageView setImage:[UIImage imageNamed:#"image1.png"]];
}
Default image name must be "Default-568h#2x.png" (not image1-568h#2x.png) try renaming the default image name and check again, you will get right screen size.
Also you can check iphone5 by macros.
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
I think content mode of your imageview is center so try this for your imageview
[_backgroundimageView setContentMode:UIViewContentModeScaleAspectFill]

set background images for Iphone 3g, Iphone 4s and Iphone 5

I want to set the background image of a view. I use three images: backgroundimage.png (size 320 x 480), backgroundimage#2x.png (size 640 x 960) and backgroundimage-568h#2x.png (size 640 x 1136)
that works for iphone 3g size. But when I test it for retina size the background image is just a small part of the original image. I think, that I have to downscale the image somehow, or set a frame for it, but I just don't know how.
Thanks for any help ;)
thats the code:
self.view.backgroundColor = [UIColor clearColor];
UIImage *backgroundImage = [[UIImage alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
backgroundImage = [UIImage imageNamed:#"background-568h#2x"];
}
else{
backgroundImage = [UIImage imageNamed:#"background"];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
My first guess is because of the misuse of colorWithPatternImage. This should only be used if you have a pattern image that you wish to have tiled. Instead try creating a UIImageView the size of the view, and then adding it as a subview of self.view.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];