Why is the slider's minimumValueImage in iOS gets blurred? - ios

I am using 24x24 point png images for this slider's minimumValueImage and maximumValueImage, But when I run them on iPhone simulator it appears but blurred/stretched. Can anyone help me how to resolve this issue.

There are three possible screen resolutions, so every image in your app needs to come in three versions. Here's how:
Make three images in three sizes: in your case, that would be 24x24, 48x48, 72x72.
Edit the asset catalog. Create an image set. Give the image set a name.
Select the image set. You will see the Universal display with three slots for images:
Drag the small image into the 1x slot, the medium image into the 2x slot, and the big image into the 3x slot.
In your code, refer to the image by the name of the image set.
Follow those instructions for every image in your app.

Related

Xcode #2x image suffix not showing as Retina in iOS

I am having difficulties with retina images.
The screenshot below shows the UICollectionView with a UIImageView contained within each UICollectionViewCell.
Within the app I have a large image 512x512 pixels called travel.png.
The green circle shows what is displayed on the app when I name this file: travel.png. The blue circle shows what I see when I update the image name to be travel#2x.png (i.e. retina naming).
I was hoping due to the large size of the image (512x512) that simply adding the #2x suffix would be enough to convert it to twice the definition (i.e. retina) but as you can see from the two screenshots, both version images show as non-retina.
How can I update the image so that it will display in retina?
travel.png:
travel#2x.png:
* Updated *
Following request in comments below:
I load this image by calling the following function:
// Note - when this method is called: contentMode is set to .scaleAspectFit & imageName is "travel"
public func setImageName(imageName: String, contentMode: ContentMode) {
self.contentMode = contentMode
if let image = UIImage(named: imageName) {
self.image = image
}
}
Here is how the image appears in Xcode before the app renders it (as you can see it is high enough definition):
The reason why you see the low quality image is anti-aliasing. When you provide images bigger then an actual frame of UIImageView (scaleAspectFit mode) the system will automatically downscale them. During scaling some anti-aliasing effects can be added at curve shapes. To avoid the effect you should provide the exact image size you want to display on the screen.
To detect if UIImageView autoscale the image you can switch on Debug->Color Misaligned Images at Simulator menu:
Now all scaled images will highlight at simulator with yellow color. Each highlighted image may have anti-aliasing artifacts and affect CPU usage for scaling algorithms:
To resolve the issue you should use exact sizes. So the system will use them directly without any additional calculations. For example, if your button have 80x80px size you should add three images to assert catalog with following sizes and dpi: 80x80px (72 dpi), 160x160px (144 dpi) and 240x240px (216 dpi):
Now the image will be drawn at the screen without downscaling with much better visual quality:
If your intention is to have just one image for all the sizes, I would suggest it having under Assets.xcassets. It is easy to create the folder structures and manage media assets here.
Steps
On clicking + icon, you will displayed a list of actions. Choose to create a New folder.
Choosing the new folder that is created, click on the + icon again and click on New Image Set.
Choose the imageset. And choose the attributes inspector.
Select Single Scale, under Scales.
Drag and drop the image.
Rename the image name and folder names as you wish.
Now you can use this image using the image name for all the screen sizes.
TL;DR;
Change the view layer's minificationFilter to .trilinear
imageView.layer.minificationFilter = .trilinear
as illustrated by the device screenshot below
As Anton's answer correctly pointed out, the aliasing effet you observe is caused by the large difference in dimensions between the source image and the image view it's displayed in. Adding the #2x suffix won't change anything if you do not change the dimensions of the source image itself.
That said there is an easy way to improve the situation without resizing the original image: CALayer offers some control over the method used by the graphics back-end to resize images : minificationFilter and magnificationFilter. The first one is relevant in your case since the image size is being reduced. The default value is CALayerContentsFilter.linear, just switch to .trilinear for a much better result (more info on those wikipedia pages). This will require more GPU power (thus battery), especially if you apply it on many images.
You should really consider resizing the images before displaying them, either statically or at run-time (and maybe cache the resized versions). In addition to the bad visual quality, using such large images in quantities in your UI will decrease performance and waste lots of memory, leading to potentially other issues.
I have fixed, #DarshanKunjadiya issue.
Make sure (if you are already using assets):
Make sure images are not un-assigned
Now use images in storyboard or code without extensions. (e.g. "image" NOT "image.png")
If you are not using images from assets, move them to assets.
Demo Projects
Hope it helps.
Let me know of your feedback.
I think images without the #2x and #3x are rendered for devices with low resolutions (like the iphone 4 an 3G).
The solution I think is to always use the .xcassets file or to add the #2x or #3X in the names of your images.
In iOS, content is placed on the screen based on the iOS coordinate system. for displaying an image on a standard resolution system having 1:1 pixel density we should supply image at #1x resolution. for higher resolution displays the pixel density will be a scale factor of 2.0, 3.0 which refers in the iOS system as #2x and #3x respectively. That is high-resolution displays demands images with higher density.
For example, if you want to display an image of size 128x128 in standard resolution. You have to supply the #2x and #3x size image of the same. ie., 256x256 at #2x version and 384x384 image at #3x version.
In the following screenshot, I have supplied an image of size 256x256 for 2x version to display a 128x128 pixel image in iPhone 6s. iPhone 6s render images at #2x size. Using the three version of images such as 1x, 2x and 3x with asset catalogue will resolve your issues. So the iPhone will automatically render the correct sized image automatically with the screen resolution.

Images sizes for different screen

I have developed the IOS app, and it is my first app ever. I have 2 real devices. Iphone 5 and Iphone 6 plus.
I have created a UITable and in that under the custom cell I am showing small images let say 20 * 20 to represent something followed by its text.
For example I am using location icon and then I write its location in string. and both are horizontally aligned in a cell.
when I run it on the emulator Iphone 8, it shows the icon and the
screen design is as expected. but when I run it on my both devices it
is not showing me icons there it is only showing location in text form
but location image is just not there in both devices.
So I know I am doing something wrong so my summed up questions are
What is the size should I select as image/icons like button icons ?
how to put images in the project? I know it is like drag and drop in assets file? but is not there a way ?
I am not getting on how to make image and then postfix it with #2x #3x and from which size I need to start and then How to do it ?
I followed a tutorial over youtube but that was for app icon, and my app icon are visible on each devices, and looks good. But I am really confused about other icons that I have to use inside the app. and about their sizes and about how to put them in project
Please help me, and discuss it with me instead of links of pages because I have read too much on it but still a dumb head. please help me
Here is how to add an image to your project:
In the Project Navigator, open the Assets.xcassets by double-clicking on it.
Control-click in the blank area below AppIcon and select New Image Set from the pop-up.
A new asset called Image will appear. Click on Image and give it the name you want to use, (for example "house").
Drag and drop 2x and 3x PNG images into the appropriate spots. If your image is 20 x 20 points on screen, then your 2x image should be 40 x 40, and your 3x image should be 60 x 60. It is up to you to make sure those images have the proper detail and are not just scaled up low resolution images. (See Xcode images explanation for more background on 1x, 2x and 3x images).
In your code, you can load the image with let image = UIImage(named: "house") and iOS will select the proper resolution image for your device. The iPhone 5 will use the 2x version, and the iPhone 6 Plus will use the 3x version.

How to handle iphone screen sizes/resolution for background images

After the iPhoneX, I am really struggling with the image sizes and naming conventions which supports all devices. Is there any way to use 3x images for 4.7, 5.5 snd 5.8 screens? What are the exact dimensions I should use for an imageview in full screen?
You can use image with .pdf format. So you need to manage only single scale image with 1x. It will support all screen sizes so you don't need to mange 1x,2x,3x png. So single image can adjust all devices and also reduce app size.
You can follow these simple steps to implement this method:
Step 1: Get your background image with 1x size in .png format and convert it to .pdf file
Step 2: Add that .pdf image in your project's Assets.xcassets and make you have to select "Single scale" in asset property otherwise you can't add .pdf formatted image.
Step 3: Add set that image in imageview and check with different devices
Feel free to ask anything. :-)

XCode 7 different images resolutions

I have an iOS application supports iOS7+, i am using now Xcode 7.
I have multiple image sizes to use for iPhone 4s, 5, 6 and 6plus sizes...
I am using image assets in XCode, but i found only 3 image nodes: 1x, 2x and 3x.
How to manipulate these different sizes with these only three options in image assets?
Edit:
in the story board; i have single viewController (assumption), this viewController contains single image, how to create single image set and put all images in this set and in the run time, every device takes its suitable image size?
In the "image assets" section of Xcode, you can add a different image set for each distinct image that you need in your app.
To add another image set for a different type of image you just click on the plus button in the bottom left of the image assets view, and then click on "New Image Set" (see image below).
From there you can add as many image sets as you would like, with the 1x, 2x and 3x for the respective devices. The 1x size represents images that will be used for non-retina displays (everything previous to the iPhone 4). Then the 2x size is used for all phones after that except for the iPhone 6 plus and 6s plus (those two use the 3x size).
Hope below mentioned link helps:
https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW1

Xcode 6.x Story board button size issues

We have added image sets to the xcassets folder. They are all named properly. When we set up a button with constraints the box for the image scales, but the image itself stays the same size on all phones... how do you set it up to keep the button image scaling to the relative size so the proportion stays the same on all screen sizes and the 1x 2x 3x images are utilized.
See screen shot here (sorry still dont have enough points to post photos so here are links)
https://www.evernote.com/l/AHGB5KrFQCtHtJAV1u5AP1eG_G1KpeMznXg
this has the proper 1x, 2x, and 3x images
Here is what it looks like in preview for the various phone sizes, notice the buttons (images of male and female do not scale).
Xcode Preview option
https://www.evernote.com/l/AHGq50vKq3tG151kfmUG4mjK0Iz6yYeg_Ck
So not 100% sure what the issue is or if this is just an issue with buttons and xcode not properly scaling based upon the 1x,2, and 3x..
any thoughts?

Resources