Scaling Images based on device size xcode - iphone

So here is my question, I have an app where i have some PNG images that are 64 pixels X 64 pixels and when the game is loaded on i-pad simulator all of the images fit perfectly but when i change the simulator to the i-phone sizes the images don't fit on the screen size right. How do you change the size of the picture to scale right for all device sizes?

U Can use Constraints for any ios devices like i-pad, i-phone..etc

You can do it either from Xcode, with autolayout, or programmatically:
let width = UIScreen.mainScreen().bounds.width
image.frame.size.width = width

I hope help you
Please check the given below image.
look all indicate point.

Related

How to set the size and background of splash screen for universal app

I am using Default.png for iPhone and Default-Landscape.png for ipad. But in case of ipad the splash screen shows only half of the image and rest is cut. It seems to be the size of image becomes double of what it should be. I am using image with width:525 and height:175 for ipad.
I also added:
UILaunchImageFile~ipad Default-Landscape.png
in my info.plist file. What might be the problem? Please guide me....
Also can i set the backgroung of splash screen to white????
The landscape iPad launch image has to be 1024x748 pixels. That's the only size that will prevent your image from scaling.
I guess the iPad tries to scale your image to a height of 748 which means the width will be 2244px. Not exactly double but something like four times the size of what you want.
Create a white image with dimensions of 1024x748 and put your 525x175 image in the middle of it.
Try the image name Default#2x.png and size would be 1024X768....

iphone - How to control images for Retina Display?

My app will download a image and display it into a UIImageView.
The image is quite large, say 600 * 600 and the UIImageView's size is 100 * 100.
So when the image is displayed, I set the UIImageView to scale it to fit.
My question is
For iPhone 3Gs, I understand the image is scaled to 100 * 100 directly and displayed in UIImageView.
But what about iPhone 4? When I do imageView.image = image, will iOS automatically scale the image to 200 * 200 first and then display it in 100 * 100 imageView?
I mean should I do anything extra to make sure that the Retina display is adapted?
Thanks
In this case, no, you needn't do anything particular. If your UIImageView is well configured (scale to fit, as it seems you've done), an iPhone4 will display your image scaled at 200x200 pixels in a 100x100 points UIImageView. No need either to download a different "whatever#2x.png" image.
You don't have to do anything specific here. Your image will be scaled appropriately by UIKit and in fact it's the UIImageView which will be affected by the Retina display, not your image. You specify a size of 100 x 100 which on non-Retina displays will hold true, but on Retina displays under the surface the physical size will actually be 200 x 200 because it'll take into account the scaleFactor.
Either way, the UIImageView will scale the image accordingly.
I have an experience that it works opposite way..so scale it for retina and iphone 3G or 3GS will display it correctly.

display image in iphone 4 retina display

I am showing a high resolution image in iphone 4 and i set the image view frame size as below :
imageFrameNormal.size.width = 470;
imageFrameNormal.size.height = 625;
but it showing full screen instead of this size. so plz can any one suggest how i show image in right size.
i am trying to check it in simulator.
Thx
You have to use the same sizes on retina and normal displays. For example, you have image view with size 100x100. On retina device you should use the same size 100x100 (no changes in your code). However you'd better use high-res image (2x size). For this you need to name it properly:
image.png - normal size image
image#2x.png - 2x size image.
When you call
UIImage* img = [UIImage imageNamed: #"image.png"];
image.png would be used on normal display and image#2x.png on retina (iOS does it automatically).
The retina display's coordinate system is not in pixels, but in "points". The iPhone display, whether retina or legacy will always be 320x480 points. When interacting with any parameters such as the frame, size, origin, etc., you will need to remember to use points instead of pixels. The OS will handle the "conversion" between points and pixels for you.
For a much more detailed explanation, see Points vs. Pixels in the Drawing and Printing Guide for iOS.

Image resolution problem in iPhone 4

I am having a problem in iphone 4. The images used in iPhone less than 4 are fine but when I upgraded to iphone 4 the images looks distorted.
Here is the link.
The image size I have used is 320 x 480.
http://img822.imageshack.us/img822/8431/download22.png
Thanks.
The fact is that the resolution of iPhone4 is 960x640 instead that 480x320 so the image is scaled with linear (or bilinear, not sure) filtering.. the result is what you get: a blurry image.
Just redo the image with the proper resolution to solve the problem, you mainly notice these kinds of artifacts because you have rasterized text on an image..
You obtain this effect whenever you resize an image to fit a wider area of pixels: the missing pixels must be filled somehow and filtering comes into play. So you will have to consider also that part of the screen is used by the top bar to have an exact sized picture.
Create a #2x suffix to each of your png that you use.
example:
Icon.png
Icon#2x.png
The runtime environment will choose the double-resolution on retina display devices.
It looks like your original image is 480x320, but you aren't accounting for the fact that the status bar is compressing your image slightly (or perhaps it does on the iPhone4 but on the older iPhones it is cropping instead).
I'd check the image view settings for that background image.

iphone 4 Simulator reporting 480x320 as the screen size?

I am debugging an application using iPhone 4 Simulator. I have selected it from the simulator menu (device = iPhone 4). When I run the app, the screen size is reported as 480x320 !!??
Is there something I have to modify on this app of mine (originally built for 3G/3gs) in order to make it run on iPhone 4 (yes, I have recreated all artwork as 960x640 and the artwork is on the bundle, but it is scaling it down to half the size... because it is running on 3G/3GS mode, instead of hi res).
running
CGRect cgRect =[[UIScreen mainScreen] bounds];
will result in (0,0,480,320).
Any clues?
thanks for any help.
Recommended read: http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html
One point does not necessarily
correspond to one pixel on the screen.
A sample project, download here.
The iPhone is making the move into resolution independence. This means that things aren't measured in pixels, but in points. Points don't always correspond to pixels.
The screen size of the iPhone 3GS (and previous) is 480x320, in both points an pixels. They correspond on these devices, but in newer devices (like iPhone 4) they do not.
The iPhone 4's screen size is 960x640 in pixels, but its logical screensize is still 480x320 in points.
This allows you to keep your frame, point and size values in their original values and still support larger resolution devices.
On iPhone 4 you need to have #2x somewhere in the name of the image file and it will be used automatically on the higher resolution devices.
When #2x images are loaded, they are loaded as their original resolution, but their size property is halved to be able to work with the logical point measurments.
For instance, an image with an original size of 960x640 will report its size as 480x320 when it's asked for.
instead of bounds use currentMode
CGSize pixelBufferSize = [[[UIScreen mainScreen] currentMode] size];
you will get actual resolution