Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Customizing the grid


In this recipe, we will learn how to customize the display of the collection view.

Getting ready

In this recipe, we will work on the CollectionViewApp project we created in the Displaying data in a grid recipe. Open the project in Xamarin Studio.

How to do it...

Perform the following steps:

  1. In the ViewDidLoad method of the controller, add the following code:

    UICollectionViewFlowLayout flowLayout = new UICollectionViewFlowLayout();
    flowLayout.MinimumLineSpacing = 20f;
    flowLayout.MinimumInteritemSpacing = 4f;
    flowLayout.SectionInset = new UIEdgeInset(4f, 4f, 4f, 4f);
    flowLayout.ItemSize = new SizeF(20f, 20f);
    this.collectionView.CollectionViewLayout = flowLayout;
  2. Compile and run the app on the simulator. The result should be similar to the one shown in the following screenshot:

How it works...

The collection view's layout can be customized through the UICollectionViewLayout class. UICollectionViewFlowLayout is a subclass of this class and offers a simple layout that we can use...