[英]How to resize uiimageview in tableviewcell that is aspect fit?
我想將UIImageView
大小調整為aspectfitmode
的確切圖像大小,而沒有Aspectfit模式附帶的額外空間。
另外我該如何調整大小,以便在UITableViewCells
顯示圖像時不會出現UITableViewCells
?
UIImage img = [UIImage imageNamed:@"ABC.jpg"];
[imageView setImage:img];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
img.size.width, img.size.height);
您應該將UIImageView的高度約束作為IBOutLet屬性,然后計算UIImage的縱橫比縮放高度。 基於此設置約束常數。
float ratio = SCREEN_WIDTH / width;
float scaledHeight = height * ratio;
//float scaledWidth = width * ratio; uncomment if required
//Should not exceed the Screen size to make the image visible at a time without scrolling.
if (scaledHeight > SCREEN_HEIGHT) {
scaledHeight = SCREEN_HEIGHT;
}
cell.imageHeightConstraint.constant = scaledHeight;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.