2016-06-09 4 views
0

enter image description hereUICollectionView 셀 크기

오른쪽 열의 그림이 잘립니다. 예를 들어 오른쪽에있는 분홍색 사자는 기본적으로 대칭이어야하지만 분명히 아닙니다. 이것이 imageCell을 구성하는 방법입니다.

func configureCellWithImage(image: Image){ 
    let iV = self.imageView 
    iV.setImageWithURL(image.thumbURL) 
    if(image.aspectRatio < 1.62){ 
     iV.contentMode = UIViewContentMode.ScaleAspectFit 
    }else{ 
     iV.contentMode = UIViewContentMode.ScaleAspectFill 
    } 

} 

그리고 이것은 셀의 크기를 반환하는 방법입니다.

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
    let size = CGSize.init(width: screenSize.width/2 - 1, height: screenSize.width/2 * 1.62 - 1) 
    return size 
} 

감사합니다. 고맙습니다.

편집 : UIView의 내가이보기에 액세스 할 어떻게 159해야한다 (201)의 폭이 이유를 모르겠어요

? 나는 CollectionView, imageCell 및 UIImageView 만 가져야한다.

enter image description here

+0

를 넣어했다, 컬렉션 뷰 레이아웃'minimumInteritemSpacing'가 1? – Johnykutty

답변

0

, 이것은 잘못 스토리 보드에 수집보기 '섹션 세트 "에서 마우스 오른쪽 속성의 값을 증가 collectionView 너비 크기를 사용하고 아래 코드를 사용하십시오.

func collectionView(collectionView : UICollectionView,layout collectionViewLayout:UICollectionViewLayout,sizeForItemAtIndexPath indexPath:NSIndexPath) -> CGSize 
     { 
      return CGSize(width: (self.collectionView!.frame.width/2)-5, height: ((self.collectionView!.frame.width/2) * 1.62) - 1) 
     } 

    func collectionView(collectionView: UICollectionView, 
     layout collectionViewLayout: UICollectionViewLayout, 
     insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
      return UIEdgeInsetsMake(0, 0, 0, 0) 
    } 

    func collectionView(collectionView: UICollectionView, 
     layout collectionViewLayout: UICollectionViewLayout, 
     minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { 
      return 0.0 
    } 

    func collectionView(collectionView: UICollectionView, 
     layout collectionViewLayout: UICollectionViewLayout, 
     minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { 
      return 0.0 
    } 

그것이 도움이되기를 바랍니다.

+0

불행히도, 그것은 작동하지 않았다. 컴파일러가 다른 UIView를 만드는 것처럼 보입니다. 제 OP 편집을 참조하십시오. – Latcie

+0

당신은'UICollectionViewCell'에 imageView를 설정하고 ImageView에서 제약 조건을 설정하면 이미지의 크기가 자동으로 변경되고 내 코드가 사용됩니다. –

관련 문제