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
Related
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 3 short questions, very related:
How do i detect if the user is using a retina device?
I want to save an image inside my app in documents, if i detect that they're using a retina display phone and save the image ending in #2x.jpg will it work as it does with imported images, where it'll automatically go for that one instead on a retina device?
If i were to reference an image which didn't exist, but a #2x.jpg version existed, would it go to that by default?
Use [UIScreen mainScreen].scale, it's 2.f when it's a retina screen.
I'm not sure, but I think it'll automatically detect #2x-versions here too (as long as you use UIImage to load them).
If it's a retina screen, it'll look to the #2x-version first, if it doesn't exist, it'll fallback to the default-version. If that version doesn't exist, it'll return nil. A non retina screen however, will never look to the #2x-version.
You call it a x2.jpg-file, however, it isn't:
Your default file is something like background.png.
Then your retina file should be like background#2x.png.
You load the image using UIImage *image = [UIImage imageNamed:#"background.png"];.
In most situations you don't need to know if it's a retina screen, iOS will handle this.
I have an app and would like to make it retina display friendly.
How exactly does the process work? What images need to be added apart from what I have?
I know the sizes should be different, but am not sure on the details?
What else needs to be done to handle retina display?
Should the device be detected and use other images if the device supports retina display?
What if there are a lot of images? And how will this effect the app size?
Thanks
A good guide to this can be found here: http://mobile.tutsplus.com/tutorials/iphone/preparing-your-iphone-app-for-higher-resolutions/
In general you just create 2 sets of images. Your original and then a new one twice as big with #2x in the name. So for image.png at size 32x32 you would have one that is twice the resolution called image#2x.png at size 64x64. In your app just always use the image.png in Interface Builder and when loading in code.
There is no need to detect the device. These images will automatically be picked up by the OS and subbed in as necessary.
good articles if you're using sprites
http://weedygarden.net/2012/04/hi-res-retina-display-css-sprites/
The main thing about working with retina image is that image name convention.
And the size of image should be 2times greater than regular1.
Example- if your icon name for regular is icon.png then it should be icon#2x.png for
retina.And second thing is size for regular is 72*72 then it should be 144*144 for Retina.
It might be helpful for you.
Thnks
I am creating an app that has images in a picker view, but I have noticed that these images appear pixelated. Currently, I have the resolution set at 72 pixels/inch. I have increased it to 300 pixels/inch, but have not noticed a change. Has anyone run into the issue?
If you are creating these images in Photoshop, changing the DPI won't change the image file. A 4x4 image will have 16 pixels. When you change the DPI, it simply changes how large those pixels are on your display. In the case of the retina display, You need to create an image that is double the size (e.g. 8x8).
YOu need to provide the same file as a "#2x" file with double the size. For example, if you have:
myImage.png #32x32
Then you also need:
myImage#2x.png #64x64
When calling the resource, you can use the same way and ignore the #2x part of the filename. IOS will do the right thing. On high density devices, it will choose the bigger file, otherwise it will choose the smaller one.
[UIImage imageNamed:#"myImage.png"]
You dont need the png, but it works with or without it. This code works on all OS's. If it is a retina display, it will use the big image, otherwise not try it.
I'd like to design a background image for my app. The image should fill the iPhone screen.
What image size that will work for 3G and 4G?
A) 320 x 480.
B) 640 x 960.
I prefer to use B as it will have more quality, will 3G resize the image to fit?
Thanks for any help.
Simply author both sizes and save the hi-res with a #2x suffix in the filename (like background.png and background#2x.png). iPhone 4 will use the hi-res image, older devices will stick to the ordinary one. See the docs for +[UIImage imageNamed::
This method looks in the system caches
for an image object with the specified
name and returns that object if it
exists. If a matching image object is
not already in the cache, this method
loads the image data from the
specified file, caches it, and then
returns the resulting object.
On a device running iOS 4 or later,
the behavior is identical if the
device’s screen has a scale of 1.0. If
the screen has a scale of 2.0, this
method first searches for an image
file with the same filename with an
#2x suffix appended to it. For
example, if the file’s name is button,
it first searches for button#2x. If it
finds a 2x, it loads that image and
sets the scale property of the
returned UIImage object to 2.0.
Otherwise, it loads the unmodified
filename and sets the scale property
to 1.0. See iOS Application
Programming Guide for more information
on supporting images with different
scale factors.
Also read the appropriate part of iOS Application Programming Guide.
Although it is trivial to resize the image to the proper size, you should prepare both 320×480 and 640×960 (and probably you need a 1024×768 for iPad too). In this way the system can choose the best image for that model.
Basically, you create a 320×480 background.png for the older models, and a 640×960 background#2x.png for retina display. Then load the image with
UIImage* backgroundImage = [UIImage imageNamed:#"background.png"];
in this way, the system will choose the best resolution automatically.