2017-11-09 2 views
1

신속하게 프로젝트를 만들고 있습니다. 이미지보기가 있고 갤러리에서 이미지를 가져올 때 이미지를 볼 때 이미지가 너비와 높이와 일치하지 않습니다. 이미지보기. 초과 근무 이미지의 폭과 높이가 코드 이미지보기 여기 보다 작은입니다 :이미지가 이미지보기에 맞지 않습니다.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cellIdentifier = "ImageTVCell" 
     index=indexPath.row 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? ImageTVCell 
     // cell?.imageView?.clipsToBounds=true 
     cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFit 
     cell?.imageView?.image=imageArray[indexPath.row] 
     return cell! 
    } 
+0

확인이 https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/ –

+0

내가 시도'.scaleAspectFill' –

+0

시도 이하지만 작동하지 않습니다 –

답변

2

사용 .aspectfill 및 코드에서 true

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cellIdentifier = "ImageTVCell" 
     index=indexPath.row 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? ImageTVCell 
     cell?.imageView?.clipsToBounds=true 
     cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFill 
     cell?.imageView?.image=imageArray[indexPath.row] 
     return cell! 
    } 
1
cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFit 

clipsToBounds을 설정하는 것은 피팅 이미지 크기입니다 당신의 이미지 뷰.

cell?.imageView?.contentMode = UIViewContentMode.scaleAspectFill 

clipsToBounds = true로 설정해야합니다. 이미지 뷰의 콘텐츠 모드 방문의 더 나은 이해를 위해

http://blogs.innovationm.com/image-handling-in-ios/

+0

감사합니다 –

관련 문제