簡體   English   中英

如何在適合方面的tableviewcell中調整uiimageview的大小?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM