I'm confused as to how I'd set a UIImageView
embedded in a UICollectionViewCell
to half the height of this cell. When I try to create constraints between the two there doesn't appear to be a height option.
Is such a thing possible without delving into code?
I think it's possible. Should take about 1 minute to do.
Try the following:
UIView
to your UICollectionViewCell
(you may need to make this transparent and covering the entire cell depending on your requirements) UIImageView
inside the UIView
(I recommend drag and drop in the Document Outline
) Document Outline
drag from the UIImageView
to the UIView
and choose Aspect Ratio
Aspect Ratio
constraint in the Size Inspector
and choose Select and Edit...
First Item
is Image View.Height
(or alter it to be this) Second Item
is SuperView.Height
(or alter it to be this) Multiplier
to 1:2
Steps 5
and 6
may be the other way round in which case use Multiplier
of 2:1
Enjoy your UIImageView
resized to half your UICollectionViewCell
! You will need to set the height of your UICollectionViewCell
elsewhere.
Update:
I've just tested this in Xcode / IB and it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.