I have a problem to understand how do I manage the various image resolution in iOS with Swift.
For example if I have an image that i use it in my app , I have to create to for various devices resolution , but after that I insert in my project the various image resolution where I have to insert it, in a special folder?.
Can you help me?
You can simply drag your images with different resolutions from finder to the Asset Catalog in Xcode.
First, you need to understand why images with 1x, 2x, and 3x resolutions are needed.
Some devices' screen have denser pixels than others. These devices have what is called "Retina Displays". Imagine that you want to display a 100px by 100px image on a normal display. Now imagine that the same image is displayed on a display where the pixels are more closely packed. Obviously, the image on the second display will appear smaller. That's not a very good user experience.
To solve this problem, you can provide 2x and 3x images. The operating system will automatically choose to use these images whenever the display is a retina display.
Now let's see how you can put the images into Xcode.
First open your asset catalog:
q
Then drag the image that you want to add to this panel:
Then you will see that your image is added:
Now do you see those 1x 2x 3x thingys? That's where you need to drag the images with higher resolutions to!
So here I dragged a 2x image to the 2x slot:
Now when your app runs on a device with retina display, the 2x image will be used!
It's rather not for image resolution but screen's pixel density. Basically you've got non-retina devices (standard) and retina ( 2xstandard and 3xstandard). So, in example if you've got 100x100 point imageView that you would like to feed with image named square.png asset you will need 3 kind of images: square.png (100x100px), square#2x.png (200x200px) and square#3x.png (300x300px).
In Xcode, put these images in something called Asset Catalog - it will handle images' size managing for you.
More info: https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/_index.html
Related
Do you know why this is happening and most important how to fix it?
Adding the key with what value?
Starting in tvOS 10 you must include a wide top shelf image, Top Shelf Image Wide, with a size of 2320px by 720px #1x. tvOS Human Interface Guidelines: Icons and Images.
If Top Shelf Image Wide is not already in your Assets.xcassets you can create one manually, or with the + Add a Group or Image Set button. For example:
The crop area is still 1920px x 720px #1x when the top shelf image is displayed on the Apple TV. So, if you're using any text or images that you don't want cut off make sure to make them centered in those dimensions. For example:
The areas in red are only used for sliding in your top shelf image when your app icon becomes highlighted on the Apple TV home screen.
EDIT:
Check your target's Build Settings.
When creating background image for xCode project in Swift, and I also want it to be compatible for all iPhone and iPad devices, do I have to create it like i created the app icon? With all the #2x names, or do i only need 1 image?
And what size should the image be?
Since XCode 6 it's possible to use vector based graphics. This gives you the opportunity to create one vector graphic and during compilation XCode creates the necessary PNGs for iOS (actually iOS 8 does not have full support for vector based graphics).
I use Sketch 3 for creating and working with assets, so there you can create an icon (or whatever) and export it as pdf (Note you have to choose 0.5x, because this is handled in XCode as the smallest icon).
For the sizes of app icons check apple documentation, else you just use the size your imageView is
What size should the image be?
The size of your images depends on how large they are on screen. For example, say you have a UIImageView that has as width and height of 100 points:
On an iPad 2 (which doesn't have a retina display) you would be
using a 1x image and so your image file would be 100x100 pixels.
On an iPhone 5 (which uses a 2x retina display) your image file would need to be 200x200 pixels.
On an iPhone 6+ (which uses a 3x display) your image file would need to be 300x300 pixels.
When creating background image for xCode project in Swift, and I also want it to be compatible for all iPhone and iPad devices, do I have to create it like i created the app icon? With all the #2x names, or do i only need 1 image?
You should have a look at Image Sets in Asset Catalogs.
From Apple:
Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary to support various devices and scale factors.
Here's some more information on them: https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/Recipe.html
To create one:
1. Create a new file. Then go to Resource and select Asset Catalog.
2. Press Next and give your catalog a name.
3. To add an Image Set, select your Asset Catalog (the .xcassets file). Then press the plus button in the bottom left hand corner and select New Image Set.
4. You can rename the the Image Set if you want, by default its name is 'Image'. This is the name you use to reference your image in code or IB.
5. Now you've got your image set you can drag and drop images into 1x, 2x or 3x. Or you can change the Devices (in the Attributes Editor) to Device Specific and select specific screen sizes for your images.
6. Now in your code you can create a UIImage using the following:
let image = UIImage(named: "Image")
// Just replace "Image" with the name of your image set.
You have to create them in different resolutions.
For more details you can have a look:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW2
You can find the right resolutions at the point: "Launch file or image"
In my Windows phone 8 app, I am binding web-URL to Image control.
I have two pages, on first page i am binding a low resolution image(I Have web-URL of multiple resolutions). On next page I have to show the same Image in full screen mode so I am binding high resolution image URL. But it takes some time to load.
Then I tried to bind the same low resolution image which I have on previous page to this Full screen Image Control and then binding the high resolution image.
So my problem is here, when I am adding a low res image, its getting displayed and then I am binding a high res image. so for some time no image is appear.
Please suggest, How can i show the continuous image, Image should not be disappear.
You should use the MultiScaleImage control or wait until your High-Res image completes downloading, then re-bind your control.
I would recommend using two Image solution. Place your lo-res image into visible Image control and place your hi-res image into hidden Image control. Once hi-res image is loaded you can hide lo-res image and show hires one. For extra smooth user experience you can use animations to cross-fade images.
Subscribe to ImageOpened event so you know then image is loaded.
I have a Content Slider (All-in-one-banner sort of) on the home page of my website.
Every time this banner slides onto the next image in the queue, the other images (png format) on my page are getting pixelated. Especially it happens in Chrome.
Images and Icons such as the logos, icons used for navigation, etc... - they get pixelated when a new slide changes on the banner.
Please help me.
Demo link (Open in chrome):
When the slides in the banner change, Look at the logo on the top and the logos to the right, and also the profile pics below,: indiaemerge.com/ieys2013
The solution I could figure out is that one should NOT use an image with large dimensions.
For example: I was trying to use an image of size 800px X 400px to fit it into a division of 200px X 50px. Because of this the image was getting distorted when slides would change.
I reduced the dimensions and resolution of the image to match the target division's dimensions and it worked.
Another way to fix this is to use an svg image file.
So the lesson to be learnt here is that always try to use an image (in case it is png or jpg) whose size meets your requirement as precisely as possible. If it is an svg image file then there won't be any problem.
I am using three20 to present a photo essay of a story I made after the February earthquake in Chile. I would like the app to display portrait type images when iPad device is in portrait orientation and landscape type images when iPad device is in landscape orientation.
So there would be two versions of every image, one cropped for portrait viewing and one cropped for landscape viewing and the app would show the version that is appropriate for the orientation the device is in.
I will crop these image versions separately. That way, the app would make full use of the screen in all orientations and users will read the story like a magazine.
Ideally, the view would change over to the corresponding image, staying where it is in the sequence of images, when the user rotates the device, so from portrait #4 to landscape #4 and vice versa, for example. But, if this is not possible, jumping back to the first image whenever iPad device is rotated is acceptable as well (push to separate TTImageViews maybe?)
The idea is to give to user the experience he is reading an illustrated story in all orientations. Can this be done? If so, can you give some clues?
If it can not be done putting a specific image in the background with the image viewer overlaying it may also be a solution. If separate fullscreen views for each orientation are not possible, then at least I would like to get rid of the black "autoresizing mask" parts of the screen..
Many thanks!
diederik