简体   繁体   English

如何在Swift中显示3 * 3 CollectionView单元的动态高度

[英]How to Display 3*3 CollectionView Cell For Dynamic Height in Swift

I want to show 3*3 Collection View Dynamic Height cell any one known how to display this 我想显示3 * 3集合视图动态高度单元格的任何一个已知的显示方式

thanks in Advance.!!! 提前致谢。!!!

Here's what you can use to have 3 * 3 Collection View regarding iPhone screen size (assuming that your collectionView frame is set according to screen size) : 这是关于iPhone屏幕尺寸可使用的3 * 3 Collection View (假设您的collectionView框架是根据屏幕尺寸设置的):

Swift 迅速

optional func collectionView(collectionView: UICollectionView,
                               layout collectionViewLayout: UICollectionViewLayout,
                                      sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    var spaceBetweenCells = 12
    var width = (self.collectionView.frame.size.width - spaceBetweenCells * 3) / 3
    var height = (self.collectionView.frame.size.height - spaceBetweenCells * 3) / 3
    return CGSizeMake(width, height)
}

Objective C 目标C

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{    
    CGFloat spaceBetweenCells = 12;
    CGFloat width = (self.collectionView.frame.size.width - spaceBetweenCells*3) / 3;
    CGFloat height = (self.collectionView.frame.size.height - spaceBetweenCells*3) / 3; 
    return CGSizeMake(width, height);
}

Hope this helps. 希望这可以帮助。

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

相关问题 tableview单元格内部的Collectionview具有动态高度单元格和动态内容swift 4 - Collectionview inside tableview cell with dynamic height cells and dynamic content swift 4 如何根据单元格中的图像快速调整CollectionView单元格的高度? - How to resize CollectionView cell height according to image in cell in swift? Swift 动态 CollectionView 高度:CollectionView 内 CollectionViewCell - Swift Dynamic CollectionView Height: CollectionView inside CollectionViewCell 在 iOS 中使用 Swift 3 的 CollectionView 动态高度 - CollectionView dynamic height with Swift 3 in iOS 如何在动态CollectionView单元之后添加静态CollectionView单元? (迅速) - How do I add a static CollectionView cell after my dynamic CollectionView cells? (Swift) 如何在 CollectionView 中将单元格高度调整为 Label 高度? - How to resize cell height to Label height in CollectionView? textView Swift的动态单元格高度 - Dynamic cell height for textView Swift 在 swift 中,如何在 Tableview 单元格中根据其内容设置 CollectionView 高度? - In swift how to set CollectionView height according to its content while it is in the tableview cell? 加载Swift时CollectionView Cell更改其宽度和高度 - CollectionView Cell changes its width and height while loading Swift 如何根据其内容创建具有动态高度的collectionview? - How to create collectionview with dynamic height as per the content in it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM