0

나는 UICollectionView을 가지고 있으며 거기에는 대기중인 사용자 지정 셀이 있습니다. 스크린 샷에서 볼 수 있듯이,이 홀수 마진이 있는데, 나는 이것이 어디에서 왔는지 알 수 없습니다. 갈색/주황색은 UICollectionView이고 회색은 UICollectionViewCell입니다.CollectionViewCell margin?

많은 맞춤형 셀이 필요하므로 해당 셀에 xib 파일을 사용하고 있습니다.

enter image description here

enter image description here

그리고 UICollectionView 생성하는 코드는이 여백을 일으킬 것이라고는 아무 상관이 없습니다.

extension DashVC: UICollectionViewDelegate, UICollectionViewDataSource 
{ 
    func numberOfSections(in collectionView: UICollectionView) -> Int { 
     return 1 
    } 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PostImageCell", for: indexPath) as! PostImageCell 
     let post = posts[indexPath.row] 
     let user = users[indexPath.row] 
     cell.post = post 
     cell.user = user 
     cell.delegate = self 
     return cell 
    } 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return posts.count 
    } 

    func setCollectionViewDelegatesAndRowHeight() 
    { 
     collectionView.dataSource = self 
     collectionView.delegate = self 
    } 
} 

UPDATE :

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize 
{ 
    let width = Int(UIScreen.main.bounds.width) 
    let height = 407 
    let size = CGSize(width: width, height: height) 
    return size 
} 
+0

크기가 collectionview 폭에 따라되지 않습니다 : 당신이 당신의 컨트롤러가 UICollectionViewDelegateFlowLayout을 준수하게하고, 다음과 같은 방법을 구현할 수있는 화면으로 넓은 당신의 세포를 만들려면! collectionViewCell의 크기를 collectionview 넓이와 동일하게 지정하십시오! –

+0

어느 마진에 대해 이야기하고 있습니까? 스크린 샷에 몇 가지가 있습니다. – holex

+0

@SaurabhPrajapati'let width = Int (collectionView.frame.width)'로 시도했지만 여전히 작동하지 않습니다. 여백이 남아 있습니다 – Dani

답변

2

귀하의 UICollectionView 폭이 375이고 UICollectionViewCell 폭 당신은 차이를보고있다 (320)이다. 셀의

- (CGSize)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout *)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    cellHeight = 407.0 
    CGSize size = CGSizeMake(screenWidth, cellHeight); 

    return size; 
} 
+0

나는 그것을 시도했지만 작동하지 않습니다. 위의 질문을 업데이트했습니다. 저것 좀 봐. 또한, 셀의 높이는 1 개 이상의 사진 및/또는 내용을 포함 할 수 있기 때문에 동적이어야합니다. – Dani

+0

'cellForItemAt'를 사용하여 407로 하드 코딩하지 않고 원하는 높이를 얻을 수 있습니다. 당신은'extension UICollectionViewDelegateFlowLayout'에 넣었습니까? 그리고 그랬다면, 중단 점/디버그 로그를 놓고 그 함수가 호출되는지 아닌지 볼 수 있습니까? – nanibir

+0

Ahhhh, 확장자로 'UICollectionViewDelegateFlowLayout'을 잊어 버렸습니다! 맞습니다. 어떻게 동적 인 높이를 얻습니까? 나는'cellForItemAt'을 사용할 수있게되었지만 그것을 달성하는 방법을 모르겠습니다. 어떤 충고? – Dani