Pinterest风格的iOS故事板布局

Pinterest风格的iOS故事板布局,ios,layout,xamarin,uicollectionview,pinterest,Ios,Layout,Xamarin,Uicollectionview,Pinterest,我想创建一个这样的设计:- 我用的是故事板,我不能让它工作。到目前为止,我有一个简单的集合视图,除了所有单元格显示两次外,它工作正常。有没有一种方法可以通过不使用任何库和为单元格设置随机高度来实现这一点 这是我的故事板:- Mycollectioncontroller public MyCollectionController(IntPtr handle) : base(handle) { } public override void ViewDidLoad () { base

我想创建一个这样的设计:-

我用的是故事板,我不能让它工作。到目前为止,我有一个简单的集合视图,除了所有单元格显示两次外,它工作正常。有没有一种方法可以通过不使用任何库和为单元格设置随机高度来实现这一点

这是我的故事板:-


Mycollectioncontroller

public MyCollectionController(IntPtr handle) : base(handle)
{

}

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    data = MakeDataForRecyclerView(pageIndex);
}

public override nint NumberOfSections (UICollectionView collectionView)
{
    return 1;
}

public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
    return data.Length;
}

public override void ItemSelected (UICollectionView collectionView, NSIndexPath indexPath)
{
    var message = string.Format ("You clicked on {0}!", cell.Title);
    new UIAlertView ("Clicked", message, null, "Okay", null).Show ();
}

public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath)
{
    cell = (MyCollectionCell) collectionView.DequeueReusableCell ("My_Collection_Cell", indexPath);
    var tag = data[indexPath.Row];
    cell.PopulateData (tag.Title, tag.ThumbnailPath);
    return cell;
}

public override void ItemHighlighted(UICollectionView collectionView, NSIndexPath indexPath)
{
    var cell = collectionView.CellForItem(indexPath);
    cell.ContentView.BackgroundColor = UIColor.Yellow;
}

public override void ItemUnhighlighted(UICollectionView collectionView, NSIndexPath indexPath)
{
    var cell = collectionView.CellForItem(indexPath);
    cell.ContentView.BackgroundColor = UIColor.White;
}

public override bool ShouldHighlightItem(UICollectionView collectionView, NSIndexPath indexPath)
{
    return true;
}

private Models.DummyModel[] MakeDataForRecyclerView(int startPosition)
{
    List<Models.DummyModel> listOf4Item = new List<Models.DummyModel>();

    for (int i = startPosition * 4; i < Math.Min((4 * startPosition) + 4, AppDelegate.myList.Count); i++)
    {
        listOf4Item.Add(AppDelegate.myList.ElementAt(i));
    }

    return listOf4Item.ToArray();
}

你的问题就在这里:

public override nint NumberOfSections (UICollectionView collectionView)
{
    return 2; // should be 1 not 2
}
要为单元格设置不同的大小,可以添加以下方法:

public override SizeF GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
{
    // return the size you want for the cell at this indexPath
} 

你能给我看一下情节提要的截图吗?如果整个视图是一个
UICollectionView
及其单元格,您会显示
UICollectionViewDelegate
方法吗?为什么要为节数返回2???!!应该是1。或者它会显示所有单元格两次。@Ismail抱歉,我现在注意到了。我把它改成了1。现在,我可以看到一个单独的部分,但高度仍然是相同的,您设置单元格大小的代码部分在哪里?@Ismail查看我的输出屏幕截图。我不确定在哪里设置单元格大小我已经解决了这个问题。但我最关心的是不均匀的细胞谢谢你的帮助。非常感谢。嘿,你能帮我删除/缩小单元格之间的空间吗?@helloworld的方法与
GetSizeForItem(
行和单元格之间的空格还有两种方法。
getMinimumineItemSpacingForSection(UICollectionView,UICollectionViewLayout,Int32):Single
节的行或列中项目之间的间距。
GetMinimumLineSpacingForSection(UICollectionView,UICollectionViewLayout,Int32):Single
节的行或列之间的间距。
public override SizeF GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
{
    // return the size you want for the cell at this indexPath
}