I have an ImageView within a Stack View. When I try to add some space to the surrounding stack view with constraints I get:
Conflicting Constraints:
Image View.top = top + 8
top = Image View.top
This is the only constraint I have within this Stack View.
I have no idea why?
You shouldn't add Constraints concerning the direction of you UIStackView.
There is an Spacing Attribute of the UIStackView for this.
For example:
In an Vertical UIStackView, if are not able to establish constraints between the Bottom of your first Item in the UIStackView and the Top of the Second Item.
Solution:
Let Interface Builder do the work for you by using the Spacing attribute of UIStackView.
Related
I have the following UI definition:
I wanted to define the constraints for the components but whenever I try to add a constraint so that the Bordered Scroll View - Table View.top is topStackView.bottom + 20, I get a constraint conflict. There is a hidden constraint where the Bordered Scroll View - Table View.t must be
topStackView.bottom + 8.
So, my question is where is this +8 constraint coming from? I assume it must be from the NSScrollView that contains the table as all the components inside seem to have Translate Masks Into Constraints.
How can I properly use Auto Layout so achieve what I want?
I haven't done much with MacOS apps, but this may solve your issue...
Delete the Bordered Scroll View - Table View.top is topStackView.bottom + 20 that you're trying to add.
You have them embedded in a vertical stack view - mainStackView - so set the Spacing on that stack view to 20.
It may not look right in Storyboard / IB, but the result should be correct (I have two buttons at the top, but that won't make a difference):
I have a scrollView with a stackView placed in it. The scrollView is constrained to the rootview. The stack view will show a xib view.
The xib views are all different lengths.
The xib views are labeled simpleVC0 and simpleVC1. The length of the simpleVC0is 2500 and the length of simpleVC1 is 1000.
My problem is that when the xib views are presented in the stack view the length of the scrollView does not change to the length of the presented xib view.
It is like the xib view is presented but the scroll view is locked at a specific length.
Here is simpleVC0 xib view. followed by it when run. When I try to scroll it doesn't allow me to scroll to the bottom of the xib view. it seems to cut the xib view off at a certain length.
Am right in saying that this is possibly an issue that may have to be resolved in code? or can it it solved souled by the constraints.
I have tried auto layout constraints however they have not worked.
I have constrained the scrollView to the rootview on all four sides.
When the root view is loaded the xibs are established using the following code:
//Different subViews for ingredients and steps
if counter == 0 {
simpleViewX = SimpleVC0().view
simpleViewY = SimpleVC1().view
stack.addArrangedSubview(simpleViewX)
stack.addArrangedSubview(simpleViewY)
}
The views are the hidden shown by changing the value of the segmented view controller. Shown below:
#IBAction func tabselected(_ sender: Any) {
switch (sender as AnyObject).selectedSegmentIndex {
case 0:
simpleViewY.isHidden = true
simpleViewX.isHidden = false
break
case 1:
simpleViewX.isHidden = true
simpleViewY.isHidden = false
break
case 2:
//calledvideo in array is the value of the counter.
calledVideo = vids[counter]
geturl()
break
default:
break
}
}
To use a UIStackView with a UIScrollView you need to allow the stack view to expand its height based on its content.
When laying it out in storyboard, give the stack view a height constraint (to satisfy IB's requirements), but give that height constraint a low Priority.
Then, when adding arranged subviews, the stack view will grow vertically.
Here's a complete example, based on the images you've shown: https://github.com/DonMag/XIBsInScrollView
You have to modify the contentSize property of your scrollView in the code. I don’t know how to deal with it with storyboards, but you can make an outlet of your scrollView and calculate the new height each times it changes (each time you add something or remove something in it)
scrollView.contentSize = CGSize(width:yourNewW, height:yourNewH)
In a brand new project, I've added a button as the top component and text field below it. I have them set to fill width horizontally. I then group them into a stackview. At this point, the stackview blows everything out.
I set the stackview constraints to 0 on all four sides. The button takes up all the space. I set a constraint for height of 30 on both objects. Things look normal again.
The problem is that I can't get any vertical space between the button and textfield. How is that done when you're in a stackview?
You can enter the Spacing for the stack view members in the attribute inspector of the stack view.
I'm trying to make a button full width in ios 9 storyboards, and am trying to create a width auto constraint, but the width constraint only seems to take an exact static number. How do I make the item go full width.
Additionally if I wanted say an imageview to be full height and adjustable width to maintain it's aspect ratio - or a size to fit fill, how would I do that with the auto layout constraints in the storyboard.
Should I be doing this programmatically in the view controller?
For the button:
In storyboard drag the left and right sides of the button to make it full width. Make sure the button is selected and add a pin constraint to the left and right (if you've dragged it full width the pin constraint should be equal to -20)
For the imageView:
The full height constraint is done almost exactly the same, although this time you need to drag the top and bottom to the top and bottom edges of the view controller and pin the top and bottom to their respective Layout guide.
You can make the image full screen in the view controller (pin top, bottom, left & right) and then edit the aspect ratio of the image in the Attributes inspector when the imageView is selected:
Hope that helps!
I have a view with one UIButton with width equal to superview width. It renders correctly for iPhone 4s,5s but for 6+ it renders as shown below. I have tried adding constraints "trailing space to" "leading space to" to make it end to end but its not working and being new to layout I am not able to figure out where I am going wrong. Any suggestion is appreciated.
There are for things you have to work out with when you use autolayout...i.e.
x position of object
Y position of object
Height of Object
Width of object
here is the image for your button constraints and how it works...
At the first stage where i pinned leading space,trailing space and height i.e gives button height, width and x position....
But still i need Y position... so i gave Horizontal and vertical center constraints....
instead of this you can use top space constrain or only use vertical constraint instead of both Horizontal and vertical center constraints for Y position....
and the output screen is
In your "Add new constraints" popup do following:
Disable "Constrain to margins" checkbox
Add left and right constraints, set constants to 0.
Add height constraint.
Click "Add 3 constraints"
That's it!