简体   繁体   English

UICollectionView 单元格大小调整问题

[英]UICollectionView Cell resizing issue

I am new to iOS app development and I am trying to understand what is the issue in iPhone 11 Pro Simulator of my layout when works well in iPhone 8 Plus.我是 iOS 应用程序开发的新手,当我在 iPhone 8 Plus 中运行良好时,我试图了解我的布局的 iPhone 11 Pro Simulator 中的问题。

Please find the screenshot below:请找到以下屏幕截图:

在此处输入图片说明

Can anyone help me out on why this is happening?任何人都可以帮助我了解为什么会发生这种情况吗?

If you require anymore information on the code, Please let me know.如果您需要有关代码的更多信息,请告诉我。

EDIT:编辑:

This is my CollectionView Attributes:这是我的 CollectionView 属性:

在此处输入图片说明

It appears that the cell is little zoomed in when it comes to the iPhone 11 Simulator.当涉及到 iPhone 11 模拟器时,单元格似乎没有被放大。

You must have to implement Size for item method and need to confirm to UICollectionViewDelegateFlowLayout .您必须为 item 方法实现 Size 并且需要确认UICollectionViewDelegateFlowLayout

As every iPhone has different width you can not set to static width.由于每部 iPhone 都有不同的宽度,因此您无法将其设置为静态宽度。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionView.frame.width, height: 150)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM