【问题标题】:set propotional size for uicollectionView cell?为 uicollectionView 单元格设置比例大小?
【发布时间】:2015-10-26 05:43:37
【问题描述】:

大家好,

我已经创建了一个 UIcollectionView 单元格。我想为所有设备设置高度和宽度比例。例如。如果 iphone 5s 上的高度为 80 和宽度为 90,那么它也应该在其他设备上是比例的。我正在使用这个方法。

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    return CGSizeMake(80, 90);
}

【问题讨论】:

    标签: ios objective-c iphone uicollectionview


    【解决方案1】:

    试试这个

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
        return CGSizeMake(self.view.frame.size.width/.25, self.view.frame.size.width/.28);
    }
    

    【讨论】:

      【解决方案2】:

      您所要做的就是将单元格的尺寸乘以您想要的任何比例。如果 80x90 是您在 iPhone 5 上想要的尺寸,请通过咨询指南 like this one 计算适当的乘数。例如,5 的点分辨率是 320 x 568,而 6 的点分辨率是 375 x 667,因此您的宽度乘数将为 375/320,高度为 667/568。 (我会让你算算。:))

      【讨论】:

        【解决方案3】:

        使用这个

        -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
        return CGSizeMake(self.view.frame.size.width/2, self.view.frame.size.width/2);
        -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
        return 0
        ;}
        
        -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
        return 0; }
        

        【讨论】:

        • 这让我的单元格看起来太大了
        • 你应该在你的单元格的情节提要中使用自动调整大小
        • 我正在使用自动布局
        • 哦,我明白了,但在我的项目中我使用它并工作..但我没有使用自动布局:D
        • 我正在使用自动布局,这就是为什么我不能使用你的方法
        猜你喜欢
        • 2015-04-04
        • 1970-01-01
        • 2021-12-13
        • 2012-11-24
        • 1970-01-01
        • 2014-07-08
        • 2016-02-29
        • 2013-07-17
        • 2020-06-26
        相关资源
        最近更新 更多