2016-07-11 2 views
0
나는이 같은 정의 셀 만들고 싶어

: 여기사용자 CollectionView 레이아웃

enter image description here

내 코드입니다 :

import UIKit 

class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { 

    @IBOutlet var collectionView: UICollectionView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     collectionView.delegate = self 
     collectionView.dataSource = self 
    } 

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
     return 1 
    } 

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 3 
    } 

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ImageCollectionViewCell", forIndexPath: indexPath) as! ImageCollectionViewCell 
     if indexPath.row == 0 { 
      cell.imgView.image = UIImage(named: "1") 
     } else if indexPath.row == 1 { 
      cell.imgView.image = UIImage(named: "2") 
     } else { 
      cell.imgView.image = UIImage(named: "3") 
     } 
     return cell 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
     let screenWidth = UIScreen.mainScreen().bounds.width 
     if indexPath.row == 0 { 
      return CGSize(width: screenWidth/2, height: screenWidth) 
     } else if indexPath.row == 1 { 
      return CGSize(width: screenWidth/2, height: screenWidth/2 - 20) 
     } else { 
      return CGSize(width: screenWidth/2, height: screenWidth/2 - 20) 
     } 
    } 
} 

내 코드에 어떤 잘못이 있습니까를?

답변

1

문제를 해결하는 방법을 모르지만 제 3 자 라이브러리가 원하는대로 정확하게 작동한다는 것을 알고 있습니다. Check this out.

원하는 결과를 얻거나 코드를보고 어떻게 수행되는지 볼 수 있습니다.

P. 코드는 Objective-C에 있습니다.

+0

고맙습니다. 나는 그것을 점검 할것이다. – Khuong

관련 문제