blurred icons on ipad - ios

I have images supporting 1x, 2x and 3x.
Images are placed into an image set into the respective 'containers': 1x, 2x, 3x.
In Image attributes, I selected 'universal'.
However, during testing we can see that the images are blurred on an ipad (tested with ipad 2).
Not sure what am I doing wrong. Do I have to explicitly select device image set (e.g. ipad image set)?
Do I have to explicitly append 1x, 2x and 3x to the image name? For example, my-image#2x.png?
I have no issues across all iphones (4S, 5, 6/+, 6s/+, se).
I looked at various answers including this one but I am still not clear why my images are blurred on an ipad.
App icon is NOT blurred!
Icons are added to the view as follows:
toolbar items - images are set in storyboard using the image set name
tab icons on UITabBarController - added via storyboard using the image set name
map annotation callout - callout button image set with:
leftButton.setBackgroundImage(UIImage(named: navigateCue) , forState: .Normal)
Should also state that all my icons follow these guidelines provided by apple.
Also, on a simulator everything is fine...
This is how my folders are set:
In Images.xcassests I have a directory called multi-res.
In this top level directory I have sub-folders associated with the 'role' of the images (e.g. toolbar).
Each of the subfolders contain image sets (e.g. pins). An image set is named as 'red' (for red pins).
Within each image set I have 3 images: <base>.png, <base>#2x.png and <base>#3x.png
I have checked all images in both finder and sketch. They are exact in size and multiples. So if the <base>.png is 24x24, the <base>#2x.png is 48x48 and the <base>#3x.png is 72x72.
Everything works fine on all iphones (4s, 5, 6/+, 6s/+, se) and new ipads.
The issue remains with old gen ipads such as ipad 2.
I followed apple's guidelines stated here.
Do I need to create images with ~ipad extension too just for ipad2?
Do I need to have a #2x-1.png, #2x-2.png? If so, how do I create all these folders under an image set?
Something else?

Related

Set images for different iphones and debug

I am currently developing an ios app and the scope is limited to iPhones only and portrait mode only.
In each screen there are images, buttons, labels and textFields. The question here is, how do I render appropriate image for device from the Images.xcassets?
What I am doing now, written below -
From Sketch design application, exporting my images for 1x, 2x and 3x (Screens designed by a UI designer)
Adding them to Xcode project (drag and drop from finder to xcode)
Add new image set in Images.xcassets (naming it as "MyImages") and drag drop my images for 1x, 2x, 3x.
In the storyboard, on a viewcontroller, adding an ImageView
For the image view, selecting Image as "MyImages" from Attribute Inspector.
Once the above steps are complete, when I test the app on simulators starting from iphone4s, iphone5, iphone5s, iphone6 and so on.. (all the simulators available on Xcode 7.3), I don't see the appropriate image is being rendered.
Is my approach correct?
Also, how do I debug a UI element on the screens? Like, how/where do I check for what image is rendered? Its size (W X H)?
Added Screenshot
#Lohith Korupolu:
The screen shot you provided is for universal size (iPhone/iPad). From the additional information provided in comments, this would lead to issues with AutoLayout constraints that would stop the image showing on screens of a smaller size than that shown in your StoryBoard.
E.g. I have replicated your issue on storyboard...
This results in the following in Simulator for iPhone 4s....
i.e. Text is there but NO IMAGE.
REASON: The autoLayout Constraints set for the larger "Universal" Screen on any of two opposite sides would make the image invisible/ disappear when viewed on a smaller screen.
SOLUTION:
1. Clear the Autolayout constraints for this selected Image in Storyboard. See next picture...
2. Add AutoLayout constraints as below x2 pictures. (Top constraint, Height + Width) (horizontally in container). Remembering to tick "Items of new constraints" for both.
3. Run Simulator for iPhone 4s... E.g.
** The same situation is occuring with the other iPhone size simulator Runs. **
****** All Working ******
They should all be 2x images for iPhones apart from the plus size iPhones which should be 3x. Is that not what you are seeing?
In terms of debugging / checking this - you can put place holder images in your assets with labels or different colour tints to distinguish them from each other and then replace them later with images that give the desired final appearance once you know that everything is working as expected.
Using 2x images for iPhones approach works fine, however, there is another more straight forward way without having to resort to multiple image files for 1x, 2x, 3x in Xcode, by use of good large quality PDF (vector).
1. Create a Large PDF of the image/Graphic image you want to use
2. Import it into 'Assets.xcassets' - drag and drop (Into Xcode)
3. Go to the utilities panel on the right for the 'Attributes Inspector' (when the image is selected)
See Screen shot (a)
Under 'Scale Factors' the selection from 'Multiple' to 'Single Vector'
Now when you got to 'StoryBoard' and add the image - Simply select the PDF's name.
Xcode will automatically render it to correct size etc at run time for you. All the work is done by Xcode.
Exceptions:
It does not work well with images for icons inside the TabBar or Navigation Bar Items.
Note:
Vector graphics are sharp and ideal for High Definition (HD), but although Xcode accepts the Image Asset as a vector from the PDF, it doesn't seem to keep the vector but converts it into an actual image with pixelation problems when zoomed in, from a HD perspective.

How to force universal app on iPad into scale mode?

I created an universal iOS app. On all iPhone variants I want native resolution without scaling, so I created splash screen images for all available sizes in images.xcassets/LaunchImage.launchimage and set them all in Xcode:
Now, this works very well for all iPhone versions up to the biggest iPhone 6 Plus.
On iPad (with high pixel density) though I don't want native resolution. Instead I want it to scale the app (even if it looks a bit blurry then, but that's ok).
How would I do that?
In image assets you have to provide proper size for each launch screen, You can not use the same image for two devices in launch-images ( unless you have two copies of the same image ).
If you want to make app-size smaller, implement launch screen, set its background color to your desired background color and put your logo in the center of it. You can now remove iPhone 6,6Plus images from image assets, but you still have to provide launch images for iOS 7 devices (old iPhones / iPad ).
Don't use the Asset Catalogue. Create a LaunchScreen.xib , add a UIImage inside the view. Open the attribute inspector in the right hand panel and set the view mode to Aspect Fill.
The solution was quite easy, I simply changed project type from "universal" to "iphone" and that did the trick!

iOS tab bar icons are blurry

My tab bar icons appear blurry.
I created the icons using Photoshop, and followed the iOS Human Interface Guidelines when I decided the sizes of each icons.
e.g. icon size: 30x30px png
This only happens with the tab bar. I wonder if this happens because of the resolution of the images or because of programming issues...
You're using icon size 30x30 which I assume is for 1x (iPhone<4). Since iPhone>=4 needs 2x and 3x images so you have to include that also.
Either you use images with naming conventions like
star.png // 1x = 30x30
star#2x.png // 2x = 60x60
star#3x.png // 3x = 90x90
or you can use image.xcassets and put your 1x, 2x and 3x images there and use it.
Reference Xcode Assets Catalogs
Probably because using a device with the retina screen.
Try about changing the icon's filename to xxx#2x.xxx like "facebook_icon#2x.png".
Also, be aware that you can use a PDF file (vector graphics, resolution independent) instead of PNGs, and Xcode will render the appropriate resolutions at build time for you (I don't think you can easily do this for third party icons such as Facebook, but...).
To see how this is done, create a new project using the "Tabbed Application" template, and check the asset catalog for the tab bar icon images. It does just that for the circle and square icons of the "First" and "Second" initial tabs.
Use this line of code to set image for uitabbaritem in uitabbar .
tabbaritem.image = [[UIImage imageNamed:#“image”] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

Imported assets in Xcode are huge

I'm trying to make an iOS app in Xcode and the problem that I'm having is that the images that I have imported to use are huge. I first designed my app in photoshop and then extracted each asset out separately. I made sure that everything is the correct size. Every asset adds up to the iPhone retina resolution (1136 x 640).
But when I put these assets into the storyboard they are too big and go off of the screen.
Make sure you called them like imageName#2x.png and that you put them in the 2x section in the asset catalog. Otherwise the images would be treated as non retina images and they would be displayed in the double size.
Check that you are viewing them at the 4" iPhone, since the 3,5" is only 960px height.
Or you might have a opaque status bar, navigation bar or tab bar that decreases the available screenheight.

Unable to properly load iPhone 4" image

My application, which should support iOS 5.0+ I have background UIImage, which should be load proper image depending on device. So I've created 5 images with corresponding resolutions.
img.png
img#2x.png
img-568h#2x.png
img~ipad.png
img#2x~ipad.png
Also I've set Default-568h#2x.png splash image. I then detect in viewDidLoad which device my app is running and use
[bkgImageView setImage:[UIImage imageNamed:#"img.png"]];
to load appropriate image. All resolutions are loading just fine except iPhone 4" one, which is img-568h#2x.png. If I load this one explicitly
[bkgImageView setImage:[UIImage imageNamed:#"img-568h#2x.png"]];
the scale is not correct. So how can I load 4" retina image automagically or manually?
Adding -568h to the end of the file name doesn't work. The only supported modifiers are #2x,~ipad, and ~iphone. The only case where -568h might seem to work is the launch image, where the image must be specifically named Default-568h#2x.png.
You should use auto layout (or struts and springs) to adjust your screen accordingly.
Your problem is that it's automatically stretching an image that's already large enough.
The solution:
If you load the image explicitly for that device, you should load "image-568h", and let it automatically add the #2x. That way, it knows that it's a high resolution image and doesn't attempt to stretch it.
Additionally, rather than detect the device, you could design the image with the extra space at the bottom to fit the 4" screen, set the image to Aspect Fill, and let it clip for smaller devices.

Resources