How to make UIImageView load retina and non-retina images - xcode

I'm new in iOS programming and I don't know how to make UIImageView load content depending on the screen that is running the app. In my case i have a 100 frames animation. Is possible to scale the images for non-retina displays (the images are in 640x960 resolution) automatically using code? Thanks!!

Yes. Just add normal images at your project (image1.png, image2.png, ...) and your retina versions (image1#2x.png, image2#2x.png, ...). The retina versions must have "#2x" appended at end of the name.
Just use the versions without "#2x" in your code, and the Xcode will do the rest. Additionally, you can import just "#2x" versions, use image without "#2x" in your code and iOS will downsample automatically in non-retina devices.

Related

Xcode 10 UIBarButtonItem Images Vanish On Storyboard

I am using the latest version of Xcode 10 that's available in the app store. I keep losing UIBarButtonItem images in the designer. They are visible when the app is run. I can get the images back by switching the image to a different one and then switching it back again. This is what it looks like when the images are gone:
This is what it looks like when the images are visible:
If I change one image, all of the images on the screen come back. They will generally stay until I close down and reopen the app in Xcode.
They always display correctly when run on an actual device. I have tried it on multiple iPads, an iPhone, and every device simulator that I could find. This is only an issue with images on the designer.
This is how the images are set up in Xcode:
The 1X image is 24x24, the 2X image is 48x48, and the 3X image is 72x72. All images that I am using were created in Affinity Designer. They were all saved as PNG files. This is a file with the images that I'm using for the checkmark: Checkmark Files
All of the images have the following settings:
This is what the settings for the UIBarButtonItem looks like.
So far, this is just an annoyance that is happening in multiple apps that I'm working on. I'd just like to figure out why it is happening and if it is just an Xcode bug.

Xcode Ipad Simulator Background Image Stretched

Whenever I run my app through any of the Ipad simulators in xcode, the background image is stretched or zoomed in and looks really abnormal. When I run the simulator for the Iphones the background image is fine. Does anybody know what might be causing this?
edit:
Please see the following screenshots of the launchimage (how it should look) and the background once the app is done loading.
My launchimage and how the background should look:
How the background looks once the app is done loading. Notice it is zoomed in:
I've noticed your original image has resolution of 2048x1536, which is Retina display's resolution.
Solution: Rename it adding a suffix of #2x (e.g.: if your image's called background.png, rename it to background#2x.png).

Iphone Simulator Xcode 6 on IOS 8 visualize two black bars

I have tried new app in Xcode 6 and not use storyboard. But when I have ran the app, with Iphone 5,5s,6 and 6 plus, in Iphone Simulator visualize two black bars on the top and below. Only Iphone 4s there aren't black bars.
Do you have an idea to resolve my problem?
Thanks
You need to add a Default-568h#2x.png image file that is 640x1136 to your project. I added an all black one that was in an older project. I didn't have to set anything else, which was nice. If you are building for iOS8 and later you can just use the LaunchScreen.xib instead.
In my case I was using jpg pictures for the default. Even though I had the correct file names and resolutions, it didn't work.
Switching from jpg to png solved it.
If you designed the app so that its views had the "old" screen size, and didn't design them to be responsive to different screen sizes, then the phone will add the black bars (known as a "letterbox", I think).

Xcode landscape launch image warning when not required

I am finishing up an app which only runs in portrait mode on the iPad and iPhone. As a result, I don't provide any landscape launch images - I could include them, but they would never be seen, so I'd prefer to save the space in my app.
How do I stop XCode trying to auto assign 'Default.png' and 'Default#2x.png' into the landscape images for the iPad? This causes a warning to appear, since these images are for the iPhone and so are the wrong dimensions. Alternatively, a solution to suppress the warning that appears would suffice.
Control-click on an unwanted iPad launch image in the Summary window and choose Delete. This will remove the reference to the image as a launch image for iPad. Even better, go ahead and include solid black PNG images for the unneeded launch images. They will be compressed by Xcode when it builds your app, so that they will take up virtually no space in the app bundle.
I regard the fact that Xcode automatically creates default launch images for iPhone but not iPad as a bug. I suggest you complain about this behavior at bugreporter.apple.com.
EDIT: Just to be clear, what you want is a minimal set of properly sized images with the following names:
Default.png
Default#2x.png
Default-568h#2x.png
Default-Portrait~ipad.png
Default-Landscape~ipad.png
Default-Portrait#2x~ipad.png
Default-Landscape#2x~ipad.png
This will prevent Xcode from using e.g. an iPhone launch image in an iPad slot.

#2x images do not display in XCode4 interface builder designer

I'm trying to design a xib using XCode4, but when I put down an image view that displays an #2x image xcode doesn't preview it correctly (it displays a missing image icon).
It works correctly when the app is run though.
As an example: I add a UIImageView to my view and set the image property to test.png.
In my project I add a file named test#2x.png.
In XCode 3.2 this image would have correctly displayed in IB, and the #2x version would have automatically half-sized on non-retina devices.
However in IB in XCode4 the image does not display.
Is anyone else experiencing this? If they are, it's a pretty massive issue.
Why not just add both images? AFAIK UIImage isn’t guaranteed to work like that.
I always use both sizes, having the #2x ones first, and unretining them using the free app unretiner from app store, and drop both sizes to the project. When referring to an image, instead of writing test.png or test#2x.png, I write test and xCode finds sizes to the corresponding devices, but YES! in IB, the image won't be displayed in this way, just a question marked blue screen; but that works fine when running the app.

Resources