2016-05-23 59 views

回答

0

您應該將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; 
+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);