UIKit.UICollectionViewLayout Class
Base class for specifying the layout of a UIKit.UICollectionView.

See Also: UICollectionViewLayout Members

Syntax

[Foundation.Register("UICollectionViewLayout", true)]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_6_0)]
public class UICollectionViewLayout : Foundation.NSObject, Foundation.INSCoding, IDisposable

See Also

UICollectionView
UICollectionViewController
UICollectionViewFlowLayout

Remarks

Collection Views allow content to be displayed using arbitrary layouts. Grid-like layouts can use the UIKit.UICollectionViewFlowLayout or application developers can subtype UIKit.UICollectionViewLayout to create their own flexible pattern.

The layout of the UIKit.UICollectionViewCells in a UIKit.UICollectionView is controlled by a UIKit.UICollectionViewLayout, which can be passed in to the UICollectionView(UICollectionViewLayout) constructor or can changed with UICollectionView.SetCollectionViewLayout.

Application developers can create fully custom layouts by subclassing either UIKit.UICollectionViewFlowLayout or UIKit.UICollectionViewLayout.

The key methods to override are:

MethodDescription
UICollectionViewLayout.PrepareLayoutUsed for performing initial geometric calculations that will be used throughout the layout process.
UICollectionViewLayout.CollectionViewContentSize Returns the size of the area used to display content.
UICollectionViewLayout.LayoutAttributesForElementsInRectReturns the layout attributes for all the cells and views within the specified rectangle.
UICollectionViewLayout.LayoutAttributesForItemThe layout attributes of a specific cell
UICollectionViewLayout.ShouldInvalidateLayoutForBoundsChangeReturns true if the new bounds require an update of the layout.

The following code, taken from the "Introduction to Collection Views" class, creates a circular layout, as shown in the following image:

C# Example

          public override UICollectionViewLayoutAttributes LayoutAttributesForItem (NSIndexPath path)
          {
            UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell (path);
            attributes.Size = new SizeF (ItemSize, ItemSize);
          
            attributes.Center = new PointF (center.X + radius * (float)Math.Cos (2 * path.Row * Math.PI / cellCount),
              center.Y + radius * (float)Math.Sin (2 * path.Row * Math.PI / cellCount));
            return attributes;
          }
        

Related content

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0