Auto-layout not regular across different screen size - ios

I am new to iOS platform but still been able to build my first app in the last 3 weeks. Coming from android, I was able to leverage of some of the knowledge I had to adapt quickly to swift and iOS but I struggle with auto-layout in the storyboard. I have not been able to get a flow that works.
I am currently using Xcode 11 and have tried to UIScrollView but to no uniformity. Whatever I arrange correctly on iPhone 11 deforms on iPhone 8 or lower.
I have watched different tutorials on youtube, lynda.com and pluralsight but to no avail.
What is the best possible way to use auto-layout across different screens like we have in android with constraint layout/relative layout?

I recommend using anchor constrains programmatically. Setting border relative to different items will provide autolayout in all devices. If you post a screenshot of your needs , it might be easier to provide accurate answer. Also keep in mind that superview borders in iphone 8 and lower version differ from borders in higher version according to the top notches. You need to set your views relative to safe area of the superview.

Related

Set app size to native iPhone screen size xCode

Now, before all you angry people say "hOLY DUCK THIS IS A DUPLICATE", just wait. I've seen at least 10 articles on this, NONE of which have been a help. My issue is im trying to make my iPhone app (xcode 8, swift 3.1, iOS 9 deployment)
match all screen sizes and set the app size to the NATIVE screen size on the device. I've seen the launchscreen articles, and they have been no help because they aren't specific. If somebody could either provide a tutorial or link one so I can figure this out, that would be great. Thanks all
You want to set the constraints for your views.
Here's a tutorial specifically for XCode 8:
https://www.appcoda.com/auto-layout-guide/
Here's another for Adaptive Layouts:
https://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started
At their most basic, constraints lock parts of the view to known areas (top, bottom, left, right) on the screen. Compounding constraints can be helpful for specific problems, but they get complicated quickly. If you're having problems getting them to work properly, I have found it works best to remove all of the constraints and start again with something simple and increase complexity as needed.

Manually adjusting positions of UI elements in Xcode's storyboard

Instead of having to use xcodes constraints, which I can never get to work right, is there a way to manually set where UI elements are on the screen? I noticed that if I'm on the attributes bar for the view controller, I can set simulated metrics's size to any iphone size I want.
Then I can position the UI elements on the screen where I please. When I build and run, it always mimics exactly what I set up. However, it only works for the particular size of the iphone I specified. Is there a way to do all the sizes manually without making several xcode projects?
Thanks!
There is multiple other solution that is not as good as constraints.
1) Use frame property of views to place them
2) Use size classes to do different placement for iPad iPhone etc
3) Use suggested constraints - you are placing views and than you can give XCode possibility to create constraints for you suggesting what you want from your views placement.
You're going to want to learn how to properly use constraints. The approach you're trying to do would have been okay when there was only one screen size, but now we have three different sizes of iPad, two watch sizes and four different iPhone sizes. Here's a link to a tutorial from Ray Wenderlich (he has some pretty good tutorials to get you started n a wide variety of things). https://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2
The auto layout in storyboard on Xcode 7 isn't my favorite, but when Xcode 8 comes out it provides device specific sizes for views that makes auto layout much easier. So maybe Xcode 8 will provide a better solution to your problem!

How to work with auto layout concept in ios

Create one app for iphone 4 inch screen in Xcode 6.1.1 develop one page successfully and run properly in iPhone 5s. and run iPhone 6 and 6+. its show the white empty page for iPhone 6 for extra height and width. how can support for all the screen in that same code.help me new for develpoment..
This is a very generic question , it is a big topic at the beginning it might be a pain in the ass but you would be amazed how powerful it is when you master it , i would say that you should read a tutorial , let me suggest the following such as :
AutoLayout tutorial
it would be much useful if you learn the adaptive UI concepts as well it is amazing a link for it would be
Adaptive Layout Tutorial
When dealing with Autolayout keep in mind that a major difference between it and using the frames is that you depend on relations between objects position and each other rather than fixed points , try to minmize usage of constants for alignments and keep it as much as possible relative for each other at the same time make sure that each object has a constraint to calculate its width, height , top and bottom positions

UITextfield Custom Position moved up because of different iPhone sizes

I have several custom UITextfields in my app. I started this app on Xcode 5 and ran on iphone 5 simulator. After Xcode updated to Xcode 6, I ran the app on iPhone 6 simulator. Now all the textfield positions moved up because of large screen size. I just wanted to know is there anything I could do so that the positions of textfields automatically get adjusted depending upon the iPhone models.
You need to rebuild your interface to handle the different screen sizes. In particular, you need to work with the AutoLayout feature to help determine how you want everything to scale/move/position based on multiple screen sizes. This can be done via the Storyboard (easier but sometimes frustrating) or in code (harder at first but more control later). I usually use Storyboards and it's worked great on several projects.
Do you want it centered and respecting your original layout and margins? a certain distance from the top or sides? everything scaled up appropriately? All these things can be done with AutoLayouts.
Check out the great tutorial here for more information:
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

How to support one xib for all iPhone devices upto iPhone 6 Plus?

I started one new iOS apllication. And that application requirement is app should support from iPhone 4 to iPhone 6 Plus. I am very much familiar with using Xib files. So far I differentiated my apps with iPhone 5 and below iPhone 5. For that I Used 2 Xib files for one is for iPhone 5 and other is iPhone 5 below according to device height I added like that. But now apple has relased iPhone 6 and iPhone 6 Plus with iOS 8 along with XCode 6. For these 4 types devices,
1) iPhone 4 2) iPhone 5 3) iPhone 6 and 4) iPhone 6 Plus do I need to add 4 Xibs or any other solution.
To learn Storyboards, now I don't have that much time because my app has already release date confirmed from Client. But I will learn about sotryboard in future definately.
I have tried with Autolayout concept, but its not worked for me. and I dont have full awarness on Autolayout concept also. Yesterday I started my new project with XCode 6, So I taken iPhone 6 view and tried to use autoresizing and autolayout but not worked for me and views are overlapping. I know for different devices creating different xibs is not good practice. For creating each device with each xib would take huge time. I am really bothering about this how to handle different devices from yesterday onwards. Please somebody help me to came out from this issue. Really highly thankful to you. If anything mistakes in my content please forgive me.
Your question deserves a longer answer than StackOverflow can provide, but there are a few pointers I can give you.
For each of your xibs, enable Size Classes and Autolayout.
Set each xib root view's size class to width Any and height Any, which I believe are the defaults.
Design your interface in a way that looks decent on this theoretical Any x Any device.
I highly recommend using a UIScrollView at the top level of any view controller's view hierarchy.
Use constraints to anchor the controls. I find it easiest to start with the control in the top left corner, anchor it to the containing view's top and left sides, and then work your way down and across until all of your controls are constrained on all 4 sides, or on one vertical and one horizontal size, along with explicit height and width. Be generous with the greater-than and less-than relationships in your constraints.
To customize for each device layout, switch the size class to the desired combination. Note that any constraints you add, change, or remove, as well as any controls that you add or remove, will be changed only for the current class size. Do this for each different size class that you're going to support. See Apple's reference for which size classes are used for each device.
Test your layouts using the Resizable Device simulators.
This is hard work, but it sure beats having to maintain a different xib for each device size.

Resources