2017-04-26 57 views
-1

[cell.imageView sd_setImageWithURL:imageUrl];iOS imageView大小不穩定

CGSize imageSize = CGSizeMake(160, 90); 
UIGraphicsBeginImageContext(imageSize); 
CGRect imageRect = CGRectMake(0.0, 0.0, imageSize.width, imageSize.height); 
[cell.imageView.image drawInRect:imageRect]; 
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 
cell.imageView.contentMode = UIViewContentModeScaleToFill; 

在的cellForRowAtIndexPath:方法,我試圖來限制tableViewCell的ImageView的具有固定大小,因爲圖像下載不同。我在這裏編寫代碼,奇怪的是第一次加載的圖像很好,但在取消選擇該行的同時更改爲原始大小。如果向下滾動查看所有數據並返回頂部,則在該行上操作時,大小不會更改。我想知道原因......

+0

請展示更具相關性的代碼。 – shallowThought

回答

0

UIImageViewclipToBounds屬性值true

imageView.clipsToBounds = true