After upgrade my xcode to 7 I am getting the issue in autolayout. I have put a container in view controller for which I set the leading and the equals width to parent view (it means that I need container on full width of screen) every thing has working fine but the issue is with the leading constraint of that container. I have to set the leading constraint constant to -20 then it would be looks perfect on 6plus, but for all other devices -16 would do the same result.
The most easiest way is to resolve your issue is by going to your Storyboard scene or nib file click on topmost view in hierarchy and finally click on Resolve auto layout Issues button from the four option available at bottom right corner and update frames.
Xcode will take care of rest.
This is happening because from Xcode 7 iOS 9, Apple wants us to leave leading or trailing space at-least by 20 points for UI perspective.
I think it would be easier to add spacing constraints from your container to the super view. If you define Leading Space, Trailing Space, Top Space, and Bottom Space as "0" without margin the container should have the exact size of your device regardless of the iOs version and device type.
Related
enter image description here
I have set the constraints from the safe area for every labels and textfields but the problem is still occurring. The app perfectly sets only on iphone 11 and iphone 12 simulators only.
(Have shared the screenshot)
I have set the constraints from the safe area for every labels and textfields
No, you don't. If you did, you would not have this problem. You have not correctly set the trailing constraints for these views. In fact, it looks like none of your views has correct constraints.
Every view must be completely configured through constraints as to its position and its size. It must, in other words, be bounded top, left, bottom, and right. Labels and text fields and buttons have an automatic height so you don't need to fix their bottoms, but all of your views need top, left, and right constraints.
I'm working on an app for iPad but when I set the contrains(so it works on iPad Pro/iPad Mini) everything moved. I don't know if I set anything wrong or if it's problems with XCode However, are there a way to just like scale up/down the screen without contrains? Or how to fix the constrains problem.
(I choose all buttons and click add missing constrains)
Picture:
IMO selecting add missing constraints is not exactly what you want. If you want your view to scale up when screen is larger, you need to set the constraints to its superview. So you just say I want it to be 10 pt from the leading edge and 15 pt from the trailing edge. By adding missing constraints Xcode probably tells the view to be xy points wide.
To set the constraints as I mentioned you need to Ctrl drag from the view to its superview and add leading constraint. Similarly for the trailing and eventually top and bottom constraints.
For the last few months I have been doing all of my layouts in code to practice with autolayout.
I have decided to go back to Storyboards and am regretting it already :-). I have been trying to do a layout with multiple views including a UIStackView and was getting many errors. I thought maybe I was doing something wrong with the StackView so I decided to delete everything apart from a button and label.
The simple view with a label and button can be seen below:
As you can see, the constraints on the label are very simple. The button in the top right (where the blue is) just has top space and trailing space. However when I run the app the label is not seen:
I am also constantly getting: An internal error occurred. Editing functionality may be limited.
Has anyone else experienced this odd behaviour?
You have set the leading and trailing of the label . This will definitely happen because you have set the wrong constraints. Check the size of your view Controller where you have set the constraints, its (Any width , Any height).
Now, check in which size you are running, its (Compact width, Regular height). If you run it in a iPad you will find your label. Since, you have not fixed the width of your label, the label gets compressed when it is run. Try setting the width of your label and remove either the leading or the trailing constraint.
Else instead you can fix your width and select either the leading and trailing and set it to "less than equal to " rather than "equals to".
While designing imagine yourself holding the object keeping in mind about all possibilities that can occur and then set the constraints accordingly. A user can run your application in any size iPhone and iPad. So, the design should be such that it doesn't affect your objects in it.
If any problem occurs try view debugging then you can definitely find out where you have done wrong.
You may need to remove label's leading & trailing space, and add add constraint call "Center Horizontally in Container" if you want to center the label.
You can learn more about autolayout in here if you do not know it well.
You have hard coded leading and trailing constraint constants. They add up to 518. That probably makes your label width negative. You don't see it in Storyboard because you're using the inferred simulated metrics. You'll see it right away if you change to an 3.5 inch iPhone.
I think a better approach would be to remove the leading and trailing constraints and center the label horizontally in the superview. You can set a fixed width on your label if you want.
As I updated my Xcode from version 5 to 6 I saw a strange things in the storyboard. Here is one example:
What my requirement was - I wanted no space between my view and the container view.
What I did - I dragged the views left/right edge so that it meets the container margin. And then I put a horizontal spacing constraint.
Earlier the value used to be -
Leading/Trailing Space to:Superview Equals:0
Now after updating to Xcode 6 it always shows -
Leading/Trailing Space to:Superview Equals:-16.000000
Why does this happen?
That's container's margin. I think it applies the default margin to the edges. If you want to set up the Leading/Trailing Space to Superview constraint then you can do so.
If you have already created the constraint then you can select that constraint and uncheck Relative to margin
Please note the Relative to margin feature is only available on iOS >= 8, the app will crash (not sure but it should) on iOS < 8.
Try to uncheck "Relative to margin"
I am working on an iOS application and it will be compatible for all devices iPhone 3.5, 4, 4.7, 5.5 inches and iPad also.
I am designing a screen it has 5 subviews, as i view this screen in different screen it does not resize properly.
I am using Auto-layout to manage that screen and I have set the every possible constraint to manage this screen.I have to manage the Subviews height and width as the devices changes.
Following are the steps taken care by me
1)Set the Equal Height Constraint for all subviews
2)Equal Width Constraint for TopView1 and TopView2 set the High priority and set the proper Horizontal spacing, Leading, trailing edges for these two top spaces accordingly.
3)Equal Width Constraint for MiddleView1 , MiddleView2 and MiddleView3 and set the High priority and set the proper Horizontal spacing for these two and vertical spaces from TOpViews accordingly.
4)Set the Width Constraint for bottomView and set the High priority and set the proper Horizontal spacing for these two and vertical spaces from MiddleViews and bottom spaces accordingly.
Prior to this i have not used auto-layout in such complicated way.
Following are the screen shotes depict my problem.
EDIT:
#Ash Furrow please see attached a screen shotes with constraints.
I am laying out the base screen on Any Width Any Height
Please anybody suggest me how should i manage this view
Hmm. Looking at what you've done and the feedback to your question, everything seems correct.
I think I see the problem. The issue doesn't appear to be with your storyboard (here in case anyone is interested), but rather the use of Xcode. Instead of changing the view controller's simulated "Size" metric, use the Assistant Editor to view a preview of whatever device you want. I've tried that, and ran the code, and in both cases they appear to work.
So to recap, use the Preview in the Assistant Editor instead of changing the view controller's properties to resize a view hierarchy.