This is the layout. The top Label text may get very long, and I expect the Label selected at the bottom to be at least 40 pt from the bottom button when there is enough space at the moment, and at least 10 pt when there is not enough space.I tried prioritizing but it doesn't seem to work, please help me. Here is part of my code.
buttonView.snp.updateConstraints { (make) in
make.leading.bottom.trailing.equalToSuperview()
make.height.equalTo(buttonView.intrinsicContentSize.height)
}
contentLabel.snp.updateConstraints { (make) in
make.top.greaterThanOrEqualTo(headerImageView.snp.bottom).offset(10.dp)
make.leading.equalTo(50.dph)
make.trailing.equalTo(-50.dph)
}
codeTextField.snp.updateConstraints { (make) in
make.top.equalTo(contentLabel.snp.bottom).offset(10.dp)
make.leading.equalTo(46.5.dp)
make.trailing.equalTo(-46.5.dp)
make.height.equalTo(50.dp)
}
tipsLabel.snp.updateConstraints { (make) in
make.top.equalTo(codeTextField.snp.bottom).offset(10.dp)
make.width.centerX.equalTo(codeTextField)
make.bottom.equalTo(buttonView.snp.top).offset(-10.dp)
make.bottom.greaterThanOrEqualTo(buttonView.snp.top).offset(-40.dp)
}
Click here to download the demo project.
Couple things...
First, you want to set Compression Resistance on your "tips" label so it doesn't get squeezed out of existence.
Second, when you give an object constraints such as:
you have not given a complete layout. ANY value between -40 and -10 would be valid, so auto-layout doesn't understand what you really want.
To fix that, based on your descriptions, you want 40-pts if possible, and at least 10-pts. So you want two constraints that say:
at least
-10 from top of viewBequalTo
-40 from top of viewB - unless there is not enough space - so give it aPriority
less thanrequired
Try this code - I added
// MARK: DonMag ...
comments where I made changes: