2016-05-23 6 views
0

aspectfitmodeの正確な画像サイズにUIImageViewのサイズを変更したいのですが、アスペクトフィットモードに伴う余分なスペースはありません。アスペクトに合ったtableviewcellのuiimageviewのサイズを変更するにはどうすればいいですか?

また、画像を表示する際にグリッチが発生しないように、このサイズ変更を行うにはどうすればよいですか?UITableViewCells

答えて

0

あなたはIBOutLetプロパティとしてUIImageViewの高さ制約があり、その後、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; 
+0

cell.imageHeightConstraint.constantとは何ですか? – farhan

+0

これはUIImageViewの高さの制約です。IBOutlet –

+0

はい、私はそれを理解しました。imageHeightConstraintを設定すると、テーブルをスクロールするまで、すべてのセルが更新されるわけではありません。 – farhan

0
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); 
関連する問題