ios - 为什么在 Collection View 中显示奇怪的线条?

标签 ios swift uicollectionview

我目前正在创建一个自定义日历,我试图在一行中显示七个单元格,但不幸的是,有些行是随机发生的,任何人都可以引导错误。我已附上屏幕截图

Screen shot of the calendar page

我已附上示例代码:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let s = CGSize(width: CGFloat(UIScreen.main.bounds.size.width / 7), height: CGFloat(UIScreen.main.bounds.size.height / 7))
    return s
}

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

func numberOfSections(in collectionView: UICollectionView) -> Int {

    return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return numDays+weekday
}

最佳答案

您可以通过UICollectionViewDelegateFlowLayout方法来管理它

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0 // OR change as you need
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0 // OR change as you need
    }

关于ios - 为什么在 Collection View 中显示奇怪的线条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45959400/

相关文章:

ios - 如何在应用程序外部的屏幕底部显示特定于应用程序的状态栏?

swift - AudioKit 的 AKAudioFile 是否总是一次读取整个音频文件?

swift - 从 __NSArrayM 中提取值

ios - 如何将应用程序与 iOS 联系人应用程序集成?

ios - 如何增加 UICollectionViewCell 高度并在 Swift 中单击按钮后显示标签

ios - UICollectionViewCell 在滚动时可见

objective-c - 从 NSDocumentDirectory 中检索所有图像并存储到数组中

ios - 奇怪的亮点 Mobile Safari

ios - 将现有的 iOS 应用程序移植到 UWP

ios - UICollectionView 单元格高度/可滚动内容表现奇怪/不正确