당신은 imageView
는 당신이 실제로 이렇게 같은 이미지 뷰의 contentMode
속성을 사용해야에 맞게 이미지 크기를 조정하려고 그래서 경우 :
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
또는 다른
cell.imageView.contentMode = .scaleAspectFit
이 유지에 대한 스위프트에 이미지의 크기와 치수를 바꾸지 않고 최대 크기의 이미지를 와 같이 imageView
에 맞 춥니 다.또한 imageView
의 크기를 기본적으로 채우는 UIViewContentModeScaleAspectFit
(또는 .scaleAspectFill
은 Swift에서)을 시도 할 수 있지만 이미지가 이미지보기보다 넓거나 크면 맞지 않는 부분이 생깁니다.여기
모두는 A의 Obj-C에서 직접 contentModes와 스위프트 소스 파일은 다음과 같습니다
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
public enum UIViewContentMode : Int {
case scaleToFill
case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent
case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped.
case redraw // redraw on bounds change (calls -setNeedsDisplay)
case center // contents remain same size. positioned adjusted.
case top
case bottom
case left
case right
case topLeft
case topRight
case bottomLeft
case bottomRight
}
편집 :
난 당신이 또한 imageView
자체의 크기를 변화에 관심이 볼 수 있기 때문에 ("텍스트를위한 더 많은 공간을 남겨두기") 스토리 보드 나 프로그래밍 방식으로 AutoLayout을 사용하여 자신의 imageView
을 추가하고 크기 및 위치를 지정하려면 실제로을 셀에 사용하는 대신 편리하고 표준화 된 도구로 사용됩니다.
당신이 익숙하지 않다면, 나는 AutoLayout 튜토리얼을 위해 google을 쓸 것이다. 아니면 "커스텀 UITableViewCell을 생성하기 위해 AutoLayout을 사용하는 것"
실제로 자신 만의 서브 클래스를 만들고 싶지 않다면, 원하는 크기로 수동으로 크기를 변경하기 위해`cell.imageView.frame = ... ' 다음 컨텐츠 모드를 설정하면 이미지가 여전히 잘 맞는 확인합니다
을이 질문을 참조하십시오. How do I make UITableViewCell's ImageView a fixed size even when the image is smaller
이미지를 –
@SyedQamarAbbas로 공유하면 이미지보기가 동적이며 표 셀의 제목 왼쪽에 표시 할 수있는 이미지가 많이 있습니다. iOS 11 이전에는 모두가 적절하게 축소되었으며 현재는 그 중 아무 것도 수행하지 않습니다. 따라서 이미지와 관련이 없습니다. – Viktor