Put UIImageView with all Supported Resolutions in iOS - ios

I want trying to place two different UIImageView at different position in my iOS project using Storyboard. In one resolution, I can able to set this properly but if I check into other resolution then its not looking properly.
Definitely I am new in iOS application development so making small mistakes.
I have actually make my layout and graphics in iPhone8 Plus resolution and here is what I have designed page in Storyboard.
Its looking proper as per my design layout but as I switched my layout say in iPhone5s then I got horrible result.
Please check below image:
As per my best understanding, I have set few constraints too. That you can see in both images. At present I just want to worries about header and footer logo UIImageView's scaling and positioning. If these two Views get solved then I will manage other Views too.
EDIT:
Here you have Footer Constraints:
#1x,#2x and #3x image resources already exist in project but as per my thinking its not get detected.
In terms of creating UI screen, I have followed reverse path. Actually I have designed graphics in 1080x1920 resolution so its my #3x and then I have cutting down size of each object respectively for #2x and #1x resources.
Please give me some help into this.

set the size of image in 1x and add the image in 3x format, for example your image name is xyz.png then it will saved as xyz#3x.png and xcode will automatically use this image on your app. you just have to calculate the size of the image in 1x set it to the view and everything will work.
Please check this and let me know in case it doesn't work.

You only need to set the constraints for your logo UIImageView's like this:
For logo_main:
top=20 (your value), bottom=20, leading=20, and trailing=20
For MainFooterLogo:
top=0, bottom=0, leading=8, and trailing=8
and set UIImageView's Content Mode to Aspect Fit:
Your problem will be solved but you need more constraint and may be a UIScrollView for your middle container view.

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.

In Interface Builder, how I do to resize correctly this image to make it device specific?

I am using the Auto Layout feature, and I would like to know if I can use different image sizes for different screen sizes.
Here's what my Storyboard File looks like.
As you can see, there is an image of a guy. How do I keep the size of image proportional for every screen size? Let me explain.
On an iPhone 4" the guy image should look a little bit smaller than on an iPhone 5.5". Is this even possible?
On an iPhone 3.5" the image should look small. On an iPhone 4" the same image should look a little bit bigger. On an iPhone 4.7" it should look even bigger, and so on.
Setting up constraints doesn't help,
Please take a look at the following image:
There are two iPhones and the guy image should look different on both the devices. On the iPhone 4S the image should look smaller to fit nicely the big grey dot while on the iPhone 6 Plus the guy image should look definitely bigger to get the most out of its screen size.
Is there any way to do it?
Thanks you.
So, you have to understand what's AutoLayout and Size Class first. AutoLayout basically helps you place the UI elements. And the Size Class enables you to have the control on the constraints you added on different screen size.
What you need to do is set different version of constraints for different screens. You can see the options in the assistant editor(right panel). They have you the options to choose apply for "All Size Classes" or "This Size Class".
Better you go check the documentation and the WWDC video. It has the complete explanation: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/EnablingAdaptiveSizeDesign.html

Making UIImageView full screen on .xib

I'm trying to implement a "Launch Screen" .xib so that my app will get "This app is optimized for the iPhone6 and iPhone6 Plus" denotation in the app store.
So I create a new Launch Screen .xib template, delete the included label, drop a UIImageView onto it, I push the pin button and I set all the "spacing to the nearest neighbor" constraints to 0, I set the UIImageView to aspect fit, and have it point to one of my asset catalogs.
When I run the app on my phone, I'm getting some very weird results as far as the positioning of the UIImageView and the size of the image in it (it definitely isn't filling out the screen with the image). Does anyone have anyone have any idea of what I'm doing wrong here?
You don't give any actual details of what you are doing, so one has to guess. There are, however, two things to keep in mind here:
Where the image is shown doesn't really have all that much to do with the position/size of the image view. It has something to do with it, but the most important thing is actually the Content Mode of the image view.
Image views under auto layout are tricky, because they are resized based on the image - unless your constraints completely determine the height and width of the image view in some other way. In all probability your constraints are not doing that.
So the problem I was having was I trying to link the LaunchScreen.xib to a LaunchImage asset catalog. This will not work, you have to link it to a normal image asset catalog and use the universal image grouping.

Same button position in relation to iPhone 5/6/6+ screen resolution in Xcode 6

I'm coding a remote control with a background (designed in Photoshop) already for the iPhone 6+ with the proper resolution, which I use with an UIImageView at full size.
I disabled Autolayout/Size Classes and set the size to Inferred. Further I uploaded all relevant LaunchImages for proper scaling.
The UIImageView scales properly for all screen sizes, but the buttons I put over the background are moving.
For example:
All buttons (over 1-9, Power Off, Menu ecc.) should always stay at the same position (in releation to the selected device and screen resolution).
I can't get it, that all buttons stay over the designed photoshop elements.
Please give me a good advice, to solve this issue.
I would recommend using size classes and Autolayout. This type of thing is exactly what they are made for.
This youtube video is a great introduction to size classes and some Autolayout:
https://www.youtube.com/watch?v=IwSTXY0awng&feature=youtu.be

Does the iPhone 5's screen require separate versions of my app's images?

I have a graphic designer that creates images and things like that for me. Do I need give him separate image sizes to be created specifically for iPhone 5, or do I build like I used to for the 3.5 inch screen? Will the images be resized automatically?
Here is one link that may help you.
Naming convention for iPhone 5 images?
and heres another
Screen size of iphone 5
Reviewing these links basically evaluates to yes you have to create separate images for iPhone 5 you will need to add -568h#2x.png to the end of each image that is for iPhone 5. You need to also create and set the launch image as well called Default-568h#2x.png are it will not pick anything up for the iPhone 5.
No it will not resize the images automatically it will select the correct image to use, it will select the one with the -568h#2x.png simple as that.
Hope this helps.
You have to provide specific files if your images are dependent on the screen ratio.
In order to conditionally use an image according to the device you can use the technique shown here.
If that's not the case, simply provide the same images and adjust the layout programmatically or within Interface Builder.
No iOS devices with a retina display can run iOS 3. You will need high resolution versions of all your pictures.
As for converting photos to work with the iPhone 5, it depends on the photo and how it's used. If the image is used as part of the background, you have two options: you can tile it, which would not require new pictures, or you will have to redesign it altogether.
As for the other pictures, whether you can work with the same ones (same size or resized) or need new ones depends on user interface decisions only you can make. If an image must retain a certain ratio, then perhaps you can resize it and place it accordingly, or maybe an entire new image would work better.

Resources