Reputation: 2958
can we set a constraint for setting UICollectionView height to relative of the Device Screen from storyboard ?? i can set it to the tableViewCell's height but how to set for the Screen Height ?? all i wanna do is make a relative constraint between Screen Height and the View(which is inside a TableViewCell) so that i can give it the hight of half of device screen
as you can see in the size inspector i can set it the constraint for my view to its superView which is TableViewCell
Upvotes: 1
Views: 238
Reputation: 6038
Your constraint is fine, you have to set the constraint as "Equal Height" between the two views, and the multiplier to 0.5 for the value to be halved. If the view 1 and view 2 aren't in the correct order (superview is half of collectionview), you must invert the "First" and "Second" views of the constraint.
From your screenshot I can see that all that looks fine, but you have a constraint conflict (red arrow). Read it and see what's wrong.
Usually that means you have a constraint that says "do X" and another that says "do Y" and are conflicting. If you know it's from your last constraint, remove it and think "why", you'll figure it out. If you don't know where it came from, chose between the given choices in the red arrow submenu. In your case, it could be the following :
Your collectionview is set to have both 50% of height, and full height, because you might have set "Top-Bottom-Left-Right" AND "height". here, you could remove bottom or top.
Just imagine yourself as Xcode, if I tell you where to put your collectionview on Left, Right, Top and Height, you don't need to know where the bottom arrives, because the height is enough. IF you do need a constraint for the bottom, it has to be set to something else than Equal, or have a lower priority.
Sometimes it means your view doesn't have all required constraints, for example "No Y constraint defined for collectionview". Just make sure you have set everything right after you've set the height.
Again, only the information in the red arrow menu (conflicting constraints) can help us determine the issue easily. I'm not gonna lie I don't really wanna read all your constraints from the left menu manually.
But with this information you should have more than enough to resolve this yourself.
Upvotes: 1