In this recipe, we will discuss using the UICollectionView
object to display data in a grid-like layout. The UICollectionView
class was introduced in iOS 6, and is a very useful control that was missed by iOS developers. Prior to UICollectionView
, the only way to display data in a grid was to create a custom control, which was not a very easy task.
Create a new project in Xamarin Studio and name it CollectionViewApp
. We will also need something to display, so add an image to the project.
Perform the following steps:
Open the
CollectionViewAppViewController.xib
file in Interface Builder and add aUICollectionView
on its main view. The following screenshot shows the object in the object browser:Back in Xamarin Studio, add the following class:
public class ImageCell : UICollectionViewCell { public const string CELLID = "ImageCell"; public ImageCell(IntPtr handle) : base(handle) { this.Initialize(); } public UIImageView ImageView...