collectionview 列之间的间距因屏幕尺寸而异 iOS
Spacing between collectionview columns differ on screen sizes iOS
我正在创建 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 上测试它时,单元格之间的间距太大,如下所示:
我怎样才能解决这个问题并在单元格之间完全没有 space?
如果您希望所有设备的行中有 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);
}
我正在创建 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 上测试它时,单元格之间的间距太大,如下所示:
我怎样才能解决这个问题并在单元格之间完全没有 space?
如果您希望所有设备的行中有 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);
}