I am trying to upgrade my app to display icons that look great on the retina screen of the iPhone 5. AS of right now I am not setting my icons using code, I'm simply selecting the image within xcode and it loads it on its own ( I don't know how to code in the icon so that's why I am doing it this way).
Anyways, when I set the icon I have to use a 24x24 icon or else it wont fit.
When I use my high-res icons 64x64 they do not fit correctly. My question is, how do I go about making it so my icons will be scaled to fit but still retain the high-res quality?
1) If your non-retina icon is 24x24, then your retina icon should be 48x48
2) You should set your icon to be the non-retina version in interface builder. The retina version will be swapped out automatically if its on a retina device, as long as you follow the standard naming scheme:
name.png (non-retina image)
name#2x.png (retina image)
Note also: if you do set an image in code, you can simply use [UIImage imageNamed:#"whatever"] and the retina image will be swapped out automatically for you too (you don't have to do if-else or anything like that).
just try to set this code in your .m file of your particular tabBar's parent view.. in viewDidLoad: method..
self.tabBarItem.image = [UIImage imageNamed:#"home#2x.png"];/// set your image name instead of home
Related
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
Anyone knows how I can replace the orignial icon with the retina version of it, if the user have a iOS with retina display?
I've tried with data-mask="[name]#2x.[ext]" but without luck.
Hope someone have a solution
You have to include two files in your project: image.png and image#2x.png. But it's not necessary to write #2x-suffix in code. Just:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
iOS will automatically detect, what image should be used.
I'm using the following approach:
Assuming I want to display a 100x40 px height image
Create a single image, 200x80 px
Specify a css width of 100 px and height of 40 px for the image
On non retina displays this will stretch the original image to 50%. For my personal taste the result looks more than OK.
On retina displays this will practically result in a 1-to-1 mapping between image pixels and device (real) pixels.
I have to mention that I didn't test this with Phonegap, but used it in a MonoTouch project, with a web container.
I'm about to resize some images, for use with buttons.
However, I think setImage will resize the images to the right size for the buttons.
My buttons are 72 x 72, according to IB.
I think I'm going to need to produce some retina size buttons too ?
What size should I create my images so that the iphone doesn't need to resize my images ?
Create 72x72px images for the normal iPhone screens and double the size for retina displays. So that would be 144x144px images for retina displays.
If your include the images in the resources folder of your project make sure to append #2x.png to the name of the retina version of your image. This way the iPhone will use this image automatically when the button is displayed on an iPhone with retina display.
For example name the 72x72px image: button.png
And name the 144x144px image button#2x.png.
Then select button.png in InterfaceBuilder or use [button setImage:[UIImage imageNamed:#"button.png"] forState:UIControlStateNormal] to set the image in code. The iPhone will automatically load the retina version when needed.
I think it would be better to create two images, One for iPhone 3 , iPad and other for iPhone 4. As per my information iPhone provides some naming convention for images in iPhone 3 and 4 device. Check out following.
http://useyourloaf.com/blog/2010/6/29/updating-for-the-iphone-4-retinal-display.html
if button is of 72X72 then for iphone 4 make image of 144X144
Hope it helps...
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've installed my iPhone app on an iPad. When I tap this "2x" button, the app gets scaled up, but it doesn't use my retina display graphics. Isn't that somewhat stupid? I am sure I did something wrong!
What must I set in the info.plist or elsewhere that the iPad will use my retina display graphics when the app is watched in 2x mode?
No, it literally just scales up the screen. It may be a bit lame but that's by design. Note that even the text is pixel-doubled.
If you want to make better use of the screen you have to make a "Universal" app.
If you use a hi-res image (not called #2x) in your app, then size the UIImageView half the size of the image it will appear crisp on the iPhone, retina, and iPad scaled up.
Please make sure your retina image naming convention is correct.
For retina image naming convention should be #2x.Suppose if your regular image name is like
icon.png then for retina it should be icon#2x.png.