简体   繁体   中英

UIImageView - Fixed width & Flexible height?

CGRect imageLocation = CGRectMake(startingXCoordinate, startingYCoordinate + detailedTitleLabel.frame.size.height + marginY, 280, 300);
self.detailedImageView.frame = imageLocation;

This is the code I've got so far. You can see the width is 280 and the height is 300 for now... In the interface builder, I also set this image view as 'Aspect Fit' to keep the ratio.

The problem here is... for some bigger or smaller images, they're located in the centre of the UIImageView and it naturally creates some extra top & bottom margins. How can I make a perfectly fitting UIImageView not ruining the ratio with 280 width?

Thank you in advance

Did you try aspect fill instead of aspect fit? That should have solved your issue, I think.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM