【问题标题】:Spacing between collectionview columns differ on screen sizes iOS在 iOS 的屏幕尺寸上,collectionview 列之间的间距不同
【发布时间】:2016-10-27 04:49:49
【问题描述】:

我正在创建一个 UICollectionView 的图像。我不希望单元格之间有任何间距。为此,我执行以下操作:-

public override nfloat GetMinimumInteritemSpacingForSection(UICollectionView collectionView, UICollectionViewLayout layout, nint section)
{
        return 0;
}

public override nfloat GetMinimumLineSpacingForSection(UICollectionView collectionView, UICollectionViewLayout layout, nint section)
{
        return 0;
}

public override CoreGraphics.CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, Foundation.NSIndexPath indexPath)
{
       if (UIScreen.MainScreen.Bounds.Size.Height > 567)
        {
            return new CoreGraphics.CGSize(100, 100);
        }
        else
        {
            return new CoreGraphics.CGSize(80, 80);
        }
}

public override UIEdgeInsets GetInsetForSection(UICollectionView collectionView, UICollectionViewLayout layout, nint section)
{
    return new UIEdgeInsets(10, 10, 10, 10);
}

使用此代码,我的单元格在 iPhone 5S 屏幕上看起来不错,但是当我在 iPhone 6 上测试时,单元格之间的间距太大,如下所示:

我怎样才能解决这个问题并在单元格之间实现完全没有空间?

【问题讨论】:

    标签: ios iphone xamarin uicollectionview uicollectionviewcell


    【解决方案1】:

    如果您希望所有设备有 4 个单元格,则根据设备宽度设置单元格大小。

    public override CoreGraphics.CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, Foundation.NSIndexPath indexPath) {
    
       CoreGraphics.CGFloat width = (UIScreen.MainScreen.Bounds.Size.Width / 4)
       return new CoreGraphics.CGSize(width, width);
    }
    

    【讨论】:

    • 感谢您的回答。这是确切的问题:)
    • 欢迎朋友,很高兴它有帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多