如何使用swift 4显示像facebook上传图片这样的collectionView?

编程入门 行业动态 更新时间:2024-10-19 17:45:12
本文介绍了如何使用swift 4显示像facebook上传图片这样的collectionView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我想完全按照上图显示 collectionView.我知道它负责 UICollectionViewFlowLayout,但无法做到.非常感谢您的帮助.这是我的代码

Hello i want to show the collectionView exactly as the above image. I know that it responsible for UICollectionViewFlowLayout, but unable to do it. Help is much appreciated. Here is my code

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let yourWidth = (collectionView.bounds.width - 4) / 3.0 let yourHeight = yourWidth return CGSize(width: yourWidth, height: yourHeight) }

推荐答案

你的答案在你的问题中,兄弟缺少一些条件

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { switch indexPath.item { case 0,1: return CGSize(width: (UIScreen.main.bounds.width - 16) / 2, height: (UIScreen.main.bounds.width - 16) / 2) default: return CGSize(width: (UIScreen.main.bounds.width - 32) / 3, height: (UIScreen.main.bounds.width) / 3) } }

更多推荐

如何使用swift 4显示像facebook上传图片这样的collectionView?

本文发布于:2023-11-26 20:53:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635151.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   上传图片   facebook   swift   collectionView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!