在 iOS 上创建网格视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17796835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a grid view on iOS
提问by ekant
I need to implement a grid view with dynamically-changing images.
我需要使用动态变化的图像来实现网格视图。
Most of the time, I use a UITableView
to create a grid, but I run into memory issues if I have a large number of images.
大多数情况下,我使用 aUITableView
创建网格,但如果我有大量图像,我会遇到内存问题。
In iOS 6, the UICollectionView
was added, but I've never used it before.
在 iOS 6 中,UICollectionView
添加了 ,但我以前从未使用过它。
What are some "best practices" and view subclasses to use when making a grid view so I don't have memory issues?
制作网格视图时要使用哪些“最佳实践”和视图子类,以便我没有内存问题?
回答by Quamber Ali
UICollectionView
is available in iOS 6.0 and later, so it can't be used if you want to support earlier versions.
UICollectionView
在 iOS 6.0 及更高版本中可用,因此如果您想支持早期版本,则无法使用它。
There are quite a open-source libraries that let you create grid views:
有相当多的开源库可以让您创建网格视图:
I am currently using AQGridView
, and I've found it to be the most robust. It works just like a UITableView
. Evadne Wu created a videoand sample projectshowing how to use it.
我目前正在使用AQGridView
,我发现它是最强大的。它就像一个UITableView
. Evadne Wu 创建了一个视频和示例项目,展示了如何使用它。
Also, if you're trying to do this without using Interface Builder, keep in mind that it'll be a bit more difficult since you have to create the views programmatically.
此外,如果您尝试在不使用 Interface Builder 的情况下执行此操作,请记住这会有点困难,因为您必须以编程方式创建视图。
回答by Rui Peres
回答by Sanjit Saluja
I have used PSTCollectionViewand it backwards compatible with iOS 5 and iOS 4.3. UICollectionView is iOS6+ only. It virtually has the same API as UICollectionView.
我使用了PSTCollectionView,它向后兼容 iOS 5 和 iOS 4.3。UICollectionView 仅适用于 iOS6+。它实际上具有与 UICollectionView 相同的 API。
GMGridViewis also a popular choice for creating grid views.
GMGridView也是创建网格视图的流行选择。
回答by Jbryson
I would go with a UICollection view. Since you've never used one, here is a good tutorial to follow: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12.
我会使用 UICollection 视图。由于您从未使用过,这里有一个很好的教程可供参考:http: //www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12。
回答by flexicious.com
Late to the party, but we have opensourced our commercial datagrid component and its free to use!
晚会晚了,但我们已经开源了我们的商业数据网格组件并且可以免费使用!
https://github.com/flexicious/iOSDataGrid
https://github.com/flexicious/iOSDataGrid
Its actually quite versatile in what it can do as compared to most libraries listed above.
与上面列出的大多数库相比,它的功能实际上非常通用。