When applying Retina 4 for the storyboard, it would give a resolution of 320points-by-480points which is 640-by-960 in pixels.
However, when adding an image for an UIView or an UIButton by dragging it from the Media library into the VC, [not programmatically]
let's say, the image has a resolution of 50-by-50 in pixels,
instead of appearing 25points-by-25points in the storyboard,
it would appear 50points-by-50points.
Is it possible to set the the conversion from pixel to point to be triggered automatically instead of having to compress the image to half later on?
Yes - the image filename must have #2x at the end, so interface builder knows it is a retina asset. You should also include a non- retina version with the plain filename.
Related
I have a table view that displays custom cells with an image of the item. I allow the user to choose a photo from there library, which will be displayed on the cell. The image is saved in the documents directory.
I am confused on how to handle the retina vs non-retina displays.
Let's say my image is 70 x 70 pixels, should I also keep a 140 x 140 pixel version for the retina display. What's an appropriate way to handle this situation?
Yes, you should have a 70x70 px file and a 140x140 px one also. If you name your normal image "CellImage.png", you should name the retina one "CellImage#2x.png".
If you are allowing the user to choose the image from their library I am assuming that you are resizing the image before placing it in the Documents directory.
If you are sure that the images will not be shared between different devices (as in iCloud) then you can simply save the image in the correct scale and forget about it. i.e. scale the image appropriately for the current device.
You could just save the image at 140x140 and have the presentation properly scaled by the size constraints of theUIImageView.
I don't know if imageWithContentsOfFile works the same way as imageNamed method or not but when calling the imageNamed method you don't specify the file's extension but rather just the bare filename and the method attempts to select the correct file without you having to specify the decorations i.e.
Image.png
Image#2x.png
Image~iphone.png
Image#2x~iphone.png
I would like to have images for my UIButtons, screen background etc in my iPhone app.
Will it work for both Retina display and normal display if I have
ButtonImage.png and ButtonImage#2x.png
Background.png and Background#2x.png
OR, should I do any extra coding so that it works for both displays?
ButtonImage.png is looking awkward on Retina Simulator. So, I should have a higher resolution image. So... please help me.
Chandu
UIImage's imageNamed: method automatically looks up the #2x images on the retina device if they're available; no additional coding is required.
If you’re putting the image in your user interface in a .xib file, or if you use the +imageNamed: class method for UIImage, then the #2x suffix is sufficient to load Retina images.
you have nothing to do, ios do the job to choose the right one
Short Answer: Yes, that is the right way to do what you want. UIImage will figure it all out for you.
However, don't forget that you can't just copy and rename a given image (say, Background.png). You need to get an image that is the same as Background.png, but four times the resolution (that's the same as double the width and double the height). Then, you can name that Background#2x.png and everything'll be peachy keen.
Here you have to use the simple image and it will work for both, Normal display as well as retina display. You just specify simple images with ButtonImage.png & Background.png in the resource bundle and retina images ButtonImage#2x.png Background#2x.png in the resource bundle.
Now you just need to specify the simple images in the code and retina image will automatically taken when running on the device with retina screen resolution i.e. iPhone 4 and later.
backgroundImageView.image = [UIImage imageNamed:#"Background.png"];
The same code will work and when iPhone 4 with retina display it will consider the image Background#2x.png from resource bundle automatically.
Let me know if you have any other question.
That's the right thing i mean whatever you are using or describing the way,but second thing
you need to do is that allocating the position for buttons.
If you will allocating position as a constant or fix by declaring x,y coordinate then it might not work,so try to allocate position of button in dynamic way so that it will take position once retina will call it.
Thanks
This may be a very simple issue, but I've been stuck with this for a week. I'm using an UIImageView to display a Dropbox branding PNG image. I see it alright in Interface Builder, but it's easy to notice a strong pixelation in the iOS Simulator and in the actual device (an iPad). Here I attach a screen capture of the IB together with the simulator:
I would really appreciate any hint.
Thanks in advance!
InterfaceBuilder is a completely different environment than iOS or even the simulator. Layout and such should translate, but the way everything looks should always be judged (and therefore designed for) the end product.
It looks like your image is being stretched slightly. There are any number of reasons for this. The first thing to check is the resizing mask on your UIImageView. It's generally bad for UIImageViews to autoresize - for this very reason.
By the way, autoresizing is UIKit's way of making sure that subviews still fit/look good when their parent view changes size. You can specify how much you want a subview to move around, also how much you want it to stretch. Read about it here.
What you will want to do is design your view -- answer the question: how big do I want this image to be in the final product? -- and then make the actual png that size (also produce an #2x variant that is double the size for retina displays). Then, when you design in IB, make your UIImageView that size as well, and make sure that the autoresizing settings are set to prohibit stretching.
This ought to fix your problem.
Check to make sure the size of the image matches the size of your UIImageView. If the image happens to be smaller than the target image view, it will stretch to fill it which could cause pixelation. Also, if you are running the new 5.1 Simulator for iPad, it will default to the new retina screen, which means you will need the #2x sized images to prevent pixelation there.
I have an application containing number of images, custom buttons having images and number of labels.
My problem is to resize those buttons,images and labels according to iphone 4 as wel as iphone 3.
i know that images named #2x are used for high resolution, but I cant find any way to enlarge my custom buttons and labels and also those images which didn't define in code.
how do I get their exact position??
Although screen resolution of iPhone is 640x960, screen dimensions for UIKit are still 320x480 so normally you don't need to adjust coordinates for your UI elements specifically for iPhone4.
If you have '#2x' images for retina display then system will automatically draw them appropriately in the frame you had for normal display.
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.