I'm trying to achieve a hard coded layout where two text views should be stacked on top of each other and centered in a parent UICollectionViewCell:
----------------------
| |
| This is text |
| Also text |
| |
----------------------
Due to various legacy/business reasons, I should be doing this using constraints hard coded in a subclass of UICollectionViewCell. The two text views can vary in length, but should be centered vertically in the parent view, while being on top of one another.
Is there an easy way to express this in constraints? I'm a bit new to this type of layout system, so any help is appreciated!
The app I am working with uses the Masonry (https://github.com/SnapKit/Masonry) library as well, if that makes things easier.
Let's asume that the labels are named
textView1andtextView2.What you need is to set a constraint for centering horizontally
textView1to it'ssuperview(theUICollectionViewCell), then centertextView2withtextView1(you can center to it'ssuperviewtoo) and you will have both centered.For getting it on top of one another, you have to set a constraint for setting
textView2top as thetextView1bottom.Never used Masonry, but looks like you need to have these constraints: