• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - Pinterest 风格布局 iOS Storyboard

[复制链接]
菜鸟教程小白 发表于 2022-12-12 18:21:09 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

enter image description here

我正在使用 Storyboard ,但我无法让这件事发挥作用。到目前为止,我有一个简单的 Collection View ,它工作正常,除了所有单元格显示两次。有没有办法通过不使用任何库并为单元格设置随机高度来实现这一点?

这是我的 Storyboard:-

enter image description here


我的收藏 Controller

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();
}

我的CollectionCell

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

}

public void PopulateData(string title, string placeholderURL)
{
    //lblTitle.Text = title;
    placeholderImg.SetImage(url: new NSUrl(placeholderURL),
                            placeholder: UIImage.FromFile("ic_apptitle.png"));
}



Best Answer-推荐答案


你的问题在这里:

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
} 

关于ios - Pinterest 风格布局 iOS Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033430/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap