在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:27:41  来源:igfitidea点击:

Creating a grid view on iOS

ios

提问by ekant

I need to implement a grid view with dynamically-changing images.

我需要使用动态变化的图像来实现网格视图。

Most of the time, I use a UITableViewto create a grid, but I run into memory issues if I have a large number of images.

大多数情况下,我使用 aUITableView创建网格,但如果我有大量图像,我会遇到内存问题。

In iOS 6, the UICollectionViewwas 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

UICollectionViewis 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

I would go with UICollectionViewas you said. You can actually see this answerI gave, where you can see already made libraries.

我会UICollectionView按照你说的去。您实际上可以看到我给出的这个答案,在那里您可以看到已经制作的库。

回答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.

与上面列出的大多数库相比,它的功能实际上非常通用。

http://www.ioscomponents.com/Home/IOSDataGrid

http://www.ioscomponents.com/Home/IOSDataGrid