I'm new to iOS development and I'm having some issues with the auto layout feature in Xcode 7.
As the image attached, my circle progression view doesn't scales fine for the 3.5" iPhone and it certainly looks fine with the other size classes.
Is there a minimum size limit for UIView in Xcode?
Also there are two text label in the circle view and no matter how I constraint them, their size just won't change across iPhone size classes.
As you might notice I have a SOS button which is a button embedded with an image I designed. I have added some constraints similar to the circle progression view but it doesn't work at all.
Is there any good guides/tutorial where it specifically teaches how to manage iOS element sizes across all iPhone size classes?
You can set the controls heights and the spacing bitween them to be related to the main view height. That will make them shrink little bit in 3.5 inches screen. You can then play around the constraints values to find the most convenient to you. like this
Related
I need to create an app with adaptive UI. for that I use auto layout and size class. but i can't get the expected result. it displays different UIs for different screen sizes. kindly guide me to create the adaptive UI(for all screen sizes). Thanks in advance.
This is indeed problem with constraints as mentioned in comments to your question. Using size classes only allows you to set constraints for all iphones at lowest level (that's why screen size for size class Compact x Regular is same for all iphones in xcode).
It is difficult to help you, without knowing all of your constraints. My advice is, use Preview assistant, where you can see all of your devices and generated UI. By opening this Preview assistant, tap on bottom "+" symbol and add device you wish to inspect.
As you can see on this screenshot, in my storyboard, there are margins around the middle view, however on iPhone 4, where width is smaller, these margins are lower (they have lower priority as constraint), while view retains it's width/height.
I'm a bit stuck and any help would be greatly appreciated!
I'll give you a quick overview. I have designs for a screen that were built in sketch using an iphone 6 screen size, then redesigned to fit and look right for an iphone 5/5s/5c, and 6 plus as those are the only devices that I want to support.
But the design portion or implementing the designs for just one specific screen size is easy and I understand that part. Where am I'm lost completely, is how to implement a design in one view controller that looks the way that it should in all the screen sizes I designed for.
I've gone through more than a few auto layout and size class tutorials and not sure how I properly use them so that the app recognizes "this is an iphone 5, use these image sizing and placements instead, and this is an iphone 6 plus, use these" and so on.
Everything I've seen to this point regarding auto layout and constraints only use 1 set of numbers to judge distance from elements for example, but all screen sizes would have different distances.
What am I missing or not understanding? I know I'm looking at something improperly.
Thanks in advance for all help!
You're correct that just one set of numbers could be used to judge distances, but this can still describe how a view should appear on different screen sizes. Your problem may be that you're thinking of constraints as describing the frame of your view? (Which obviously has to be different on every device). I find it more helpful to think of constraints as describing how each edge of my view relates to another view.
For example here's a view controller I setup with all the same constraints and how it would look on different devices. The constraints describe how the large grey view is pinned it's left and right edges 20 points from the left and right edges of its container view. It's pinned to 8 points from the top and 8 points from the top of the label. The label is centred vertically and horizontally and it has intrinsic content size. Each button is pinned 20 points from the bottom edge with button 1 and 2 being pinned to the 20 point from the left and right edges respectively.
I don't know if that helped or if that wasn't the answer you were after and you need to arrange your views differently depending on the device: you can tell Xcode which device size and orientation the constraints you're creating are for, using this button in Interface Builder.
Use it to select a device size/orientation. After, any constraints you create will only be used on that device. By default any width and height are selected so normally your constraints are applied to all devices.
Also, you cannot choose which devices you want to support, only the iOS version.
Good day, friends!
I have a design for my first app. It is great, I love it, but I can't implement it. The problem is - I started to do it for iPhone 5 size, and only later realized that iPhone 4 doesn't fit in proportions at all.
I tried to use new adaptive layout in IB, but sizes of elements of my interface are too different.
Here is an example of design: profile screen.
There are 3 main views:
top with picture - 238 pt height
middle with properties - 220 pt height
bottom with buttons - 90 pt height
This are sizes for iPhone 5. I can scale it to fit new models, but I can't find a way to adapt it to iPhone 4.
MY QUESTION IS: what is the best way to deal with Auto Layout in my case?
Is it even possible to do this in IB using single storyboard?
Or the only way is to create constraints programmatically for all the viewControllers in the app?
Thank you very much for any ideas!
Could you create some variables that representing proportions of your elements. And in that way create a solution for every screen-size in once?
E.g. if your image width = device-width
and Image height = image-width *(16/9)
(this is no real code, but example on how it could work in the theory)
The answer appeared simple. I looked in the wrong way: tried to make interface look in Interface Builder - which seams doesn't make any sense. Right way is to simply create IBOutlets for some of the constraints and change them on the fly depending on screen size.
This will use magic numbers and a lot of place for properties in viewController file, but it will work at least.
I have built a UI for iPhone 6 using the storyboard.
NOTE: Autolayouts are enabled
The UI elements are positioned with constant constraints relative to other elements.
When i run the app on the simulator for iPhone 6 it works completely fine, the elements are positioned correctly.
The issue happens when i run the app on iPhone 6 plus and iPhone 5
On iPhone 6 and iPhone 5 the constraints have constant values and the UI gets distorted due to the change in the screen size.
I have gone through the raywenderlich blog for autolayouts
How do i scale the current UI up/down based on the screen size?(if there is a way), since they share the same aspect ratio?
EDIT:
I have hosted a small demo here. I would like to build a single UI and scale it across the form factors.
Here I've attached a project with the constraints setup. There's probably plenty of ways to set them up to get what you want. This is just one way to do it.
Hopefully this link will work.
This link is broken as of today 7 April 2016 http://speedy.sh/zPEcq/ConstraintsPlayground.zip
There's actually some constraints that's not needed in there aswell. (Forgot to remove them) They are "greyed out", and are under the green and yellow views. You can just delete them.
Answer to comment:
To "scale" the distances you need to define what you should scale from. Is it the width of the screen? What scale should it be? Should there be a max distance? a min distance? You can do almost anything with constraints, but it's sometimes a real mess due to xcode being a b*tch.
Here's an example of how you can scale the distance between two views according to the size of the screen. The gray views are just spacing views, because you need to make aspect ratio from width to width for the spacing view and the container view. The spacing views should have clear color in production:
This link is broken as of today 7 April 2016 http://speedy.sh/B7R95/ConstraintsPlayground-2.zip
The UI elements are positioned with constant constraints relative to other elements.
In that case it should be sufficient to not give the UI elements a constant width and height. In that case iOS will stretch the UI elements to fulfill the constant constraints between the different UI elements.
How do i scale the current UI up/down based on the screen size?(if there is a way), since they share the same aspect ratio?
You can set constraints to preserve the aspect ration of your elements but I don't think this is what you are looking for. Generally you don't need to think about aspect ratios. Just think about how your UI should behave if the screen is wider or taller.
As Spoek already pointed out it would be very useful to have access to your storyboard to figure out the problem. If you don't want to hand out your storyboard you may want to update your question with screenshots and a description of what constraints you put in place.
I am using Xcode 6.1 and in one of the views I have, contains many labels. However, these labels look different in each different devices. Although I have add constraints to all the labels, but still facing the same issue.
How can I get the same view layout across all devices?
How can I make the width and height for each label is flexible, depends on the screen size?
Do I need to design different xib for each device?
The following images showing the result am getting, with auto resize enabled, and constants been added.
on iPhone 6
on iPhone 5
on iPhone iOS 7.1
We have provided with a simple solution . Using Aspect ratio constraint we can get a relative look in all device screens.
I had the same issue and I found this >>
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
So when designing for lowest to highest screen resolution we can't set a specific width and height for all controls as it may look weird. So using this constraint we can have a relative look for all screens.
If you don't want to use constraints or you want to keep the same width & height , you can add scrollview to hold all controls. For that you can set a resizing frame for scrollview with fixed content size .
To solve this...
1) Go to xib file and uncheck the Auto layout
2) Then set the autosizing manually in the following manner for each and every subview.
Use self.view.bounds.size.width to get the width of screen, then use relative value to initialize all labels.
One soultion is that you can Design a story board for each screen size like one for iphone 5, one for iphone 6 and one for iphone 6+ and in your AppDelegate method "didFinishLaunchingWithOptions" you can get the screen size and popup corresponding storyboard
in this wasy you can set different constraints according to different screen size