ios - UICollectionView 单元格大小调整

标签 ios swift uicollectionview

enter image description here

右栏图片被切断。比如右边的粉色狮子应该是基本对称的,但显然不是。这就是我配置 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 的宽度是 201。它应该是 159。我如何访问这个 View ?我应该只有 CollectionView、imageCell 和 UIImageView。

enter image description here

最佳答案

尝试增加 Storyboard Collection View “部分插入”中右侧属性的值

Scale section of Collection View

关于ios - UICollectionView 单元格大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37717260/

相关文章:

ios - wait_fences : failed to receive reply: 10004003 - viewDidLoad

swift - 应用加载后更改 TabBar 颜色

ios - Tap Gesture Recognizer 落后一次

ios - 支持 iOS 10 的 Xcode 7.3.1

ios - 在 CGPath Scale 中遇到问题

ios - 为什么从自定义单元调用时 UIkeyboard 没有动画?

iOS - tableview 单元格分隔符的标准插图

ios - 如何从项目中完全删除 cocoa pod ?

ios - UICollectionView 自定义布局中间列开始较高

swift - 如何在didSelectItemAt indexPath函数下显示ViewController? (没有 Storyboard)