Xcode 8 beta 8S128d
Interface Builder and Autolayout has always puzzled me. I can simply not make it do what I want.
Example: Just need an ImageView to fill up the screen(parent), but from the top the ImageView should be be proportional to the top.
------------------
- 10% free space -
------------------
- -
- MapView -
- -
------------------
Add MKMapView to Parent View.
Pin: Right, Left, bottom = 0.
Add Equal to hight for the parent and set the multiplier to 0.90
This works for ImageView but not for MapView.
I don't have a solution but a viable Workaround
Instead of pinning the map to the borders of the enclosing container do the following
1) give equal width and heigth for mapview and its container
2) manually change height constraint from 1 to 0.99
3) center mapview horizontally and vertically in container.
You'll need some retries but it works
Edit: Caveat: Interface Builder keeps complaining about missing Y-constraint after crash (and re-entering warnings) but the app lays out well.
Struggled with this in Xcode Version 8.0 and Swift 3 - it might be, that in future revisions of Xcode this problem will be solved
Related
When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta 7. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the entire view that contains the scroll view. However, I am not getting the option to set equal widths and heights when I attempt to do so.
When I do the right-click-drag from the scroll view to the entire main view, I get the following options:
Leading Space to Safe Area
Top Space to Safe Area
Trailing Space to Safe Area
Bottom Space to Safe Area
Center Horizontally in Safe Area
Center Vertically in Safe Area
In other videos, there is an "Equal Widths" and "Equal Heights" option that I don't seem to have.
Am I doing something wrong, or did Apple change the way scroll views work in Xcode 11?
I'm using beta 7 currently
I was finally able to successfully add a UIScrollView using storyboards in Xcode Version 11.0 (11A420a) after much trial and error.
You can add the scroll view directly to the root UIView of the VC or, if you needed to, add it to another UIView under the root view as needed by your UI Design. Constrain the UIScrollView parents normally for whatever your needs are.
Here is the key : when you add the UIScrollView to the storyboard, click on the Size Inspector with the UIScrollView selected. You have to UNCHECK the box that says "Content Layout Guides".
If you do this you can set the scroll view's contraints normally (I did 0-0-0-0 to superview). Then I added a UIView to the scrollview and set it's constraints to 0-0-0-0 and a height of 900 (which is what I wanted).
This will give you constraint errors in red when you set them. They will be fixed by setting the width of the UIView equal to the width of the UIScrollView.
Set the UIView width equal to the width of the UIScrollView view by Ctrl-right clicking on the UIView, dragging to the UIScrollView, and selecting the "Equal Widths" option. This should get rid of your constraint errors.
You actually can then go back to the UISCrollView Size Inspector and check the "Content Layout Guides" checkbox, no constraint errors will appear.
Disable the content layout guides in scrollview properties.
Hope it helps.. :)
I'm trying to make a divider, so what I do is:
1) Make a new View
2) Change the background to the color I want the divider to be
3) Control click and center it horizontally on a label on top of it
4) Compile, my view is gone.
5) Remove constraints, compile, my view is there.
6) Add left and right constraint for autosize, compile, view is gone.
It also states that the height of my view is ambiguous.
How can the view be gone by merely constraining it?
Screenshot:
Your view does not disappear. It just getting zero size.
When you remove constraints it won't iOS won't layout your view that is why it's size not changing.
And in you last case with leading/trailing constrains your view will calculate its width depending on it's superview width, but since system can't calculate height it gonna change it to zero.
Other views and like labels and images have content and with a help of defined intrinsic content size they system won't resize them to zero sizes but to their content size.
here is my output I tried in swift using Xcode and tried setting constraints as I do
I got the constraints just how I want it in iPhone 5 it fits in one screen and in iPhone 4 it overflows to the bottom which is fine. But why can't I scroll down?
iPhone 5:
iPhone 4:
As you can see in iPhone 4 the bottom is not visible and all I want is to be able to scroll there.
Even without seeing how you are settings the constraints on the Interface Builder, I think that doing like below could help you to solve your problems:
Possibly you are not embeding all views in a scrollView properly. If so, select all subviews, choose Editor from menu -> Embed In -> View to wrap everything in a container. (UIView). After that select the container then choose Editor -> Embed in -> Scroll view
Set up all necessary constraints between subviews and the container ( As you did before making the view in the shared screenshot)
Set up all margins between the container and the containing scrollView to be zero ( top/ left/ right/ bottom = 0). Ensure that the scrollView fit the screen by having zero margin constraints as well.
Last but not least, set a width constraint of the container to any number you want (e.g.: 320 /375), then make an IBOutlet for this constraint
On viewDidLoad, set the constant of the container's width constraint you made in step 4 to current screen width.
That's all.
When I set the height or width of an interface object in the Watch storyboard to 1 point, it is reverted back to 2 after I unselect then select the object again. This is happening with Xcode 6.3.2.
Here is how I set the height for instance:
And after unselecting then selecting again the object:
But I really want a height of 1 point (2 pixels), which the Watch should be able to display.
I am using a WKInterfaceGroup to create a 1-point hight separator. The problem is the same with any number under 2.0 (for instance 0.5 or 1.5 are also reverted to 2.0), so it looks like Xcode storyboard editor does not accept values less than 2.0 somehow for these parameters. I found the same issue with WKInterfaceImage.
I found a simple solution, which is to set the height in code. This is a bit more cumbersome, because this means I need to set up a outlet for the group in my controller code #interface:
#property (nonatomic, weak) IBOutlet WKInterfaceGroup *separatorGroup;
The outlet should of course be set up also in the storyboard.
Then in the refresh code, I simply set up the height or width as follows:
[self.separatorGroup setHeight:1.0];
I have a scrollView that I have stretched the full width of the iOS application in Xcode. I'm using Xcode 6 and size classes so the width is set to 600X600 in the view panel. when I go to add a the constraints in IB, it shows 0 for the top, -16 for the left and right and 0 for the bottom. My question is why does it show -16? It appears as though all sides should display 0. I'm just trying to get a better understanding on how constraints work when using the new size classes.
Did you note the "Constraint to margins" checkbox? Thats what playing tricks with you I think.