Xcode 6.x Story board button size issues - ios

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?

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 choose the size/resolution for custom images for use in iOS applications?

I understand how 1x, 2x and 3x image resolutions work but I'm unsure how I go about choosing the right size/resolution for custom images in general. Imagine that we have a simple layout like the following:
Now it is up to me to create the image (in Photoshop for example) for that UIImageView. What size and resolution should the highest quality version be? Do I just use the highest screen resolution of the iOS devices that are currently available as my guide?
There is not really a best size. As you said the highest screen resolution would be the maximum, because the device obviously can not display more pixels than it has provided. If the image view is only about 1/5 of the screen size then I would use a smaller image size for memory usage.
And you only need one size for background images for example. I normally place them in my assets folder into the 2x place and I am good.
For icons i use 25x25, 50x50 and 75x75 (which will display really small on the screen)
hope I could help you a little bit…

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

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.

full screen image sizes and naming in xcode

I'm a bit confused here. If, say, I want to set an image as background (full screen) for my ios app (iphone), what are the sizes for the image I have to make? I googled and found no clear answer yet.
Using image assets gives no explanation either. I tried creating new image set, it just shows 3 slots for 1x, 2x, and 3x. How the xcode differentiate between what image to use for iphone 5 and iphone 6 (different ratio)?
EDIT
I seem to be unclear about my question. If the image for iphone 5 and 6 is the same, doesn't the aspect ratio differ? It will be stretched on one device or vice versa on the other and I don't want that. Back before the iphone 6, I just create image .png, #2x.png, and -568h#2x.png with the size 320x480, 640x960, and 640×1136. So my question is, for iphone 6 and 6+, what is the naming and size for my images?
If, say, I want to set an image as background (full screen) for my ios app (iphone), what are the sizes for the image I have to make?
You can use [UIScreen mainScreen].bounds's width & height to setup your view frame.
it just shows 3 slots for 1x, 2x, and 3x
They're not used for handling ratio of displaying, just for display solution (retina or not). You can just use xxx.png in your code, and it'll choose to use xxx#2x.png or xxx#3x.png appropriately.
How the xcode differentiate between what image to use for iphone 5 and iphone 6 (different ratio)?
UIImageView has an instance method called -setContentMode:, you can use UIViewContentModeScaleAspectFill mode for displaying in different devices w/ different ratio, i.e., some parts will be cut off.
This link should give you an overview of the differences between the 1x, 2x and the 3x image assets which we get once we create a new image asset.
http://9to5mac.com/2014/08/29/support-for-3x-image-assets-found-in-latest-ios-8-beta-ahead-of-larger-display-iphone-6/
Also when you create a new image asset, you can select image for specific devices such as (iPhone and iPad), if you are only developing for certain devices.
Select the devices as "Device Specific" from the Image Set Shown on the right side of the image.
As for you question, iPhone 5 and iPhone 6, xcode will take the same image assets i.e. 2x, for iPhone 6 Plus it takes the 3x image.
App Icon and Launch Image
Now for the App icon and the Launch image, this following link will guide you through.
http://www.iphonelife.com/blog/31369/unleash-your-inner-app-developer-managing-images-xcode-5-asset-catalogs
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html
for the launch image there are different options available, such as you can individually set images for the landscape and portrait images for different devices.

Resources