Adrian Secord 8c3af252be Adding AUTHORS and removing CONTRIBUTORS.txt.
We can credit any contributor who would like to be credited this way, by adding them on request to the AUTHORS file. The copyright statement changes are required for this to work. Note that this has...

Summary:

We can credit any contributor who would like to be credited this way, by adding them on request to the AUTHORS file. The copyright statement changes are required for this to work. Note that this has no legal change, since the contributors always retained their copyright despite the copyright notice, but it's a nice acknowledgement.

Changed copyright statement to include non-Google authors.

Command run:

find * \( -name '*\.m' -or -name '*\.h' -or -name '*\.swift' \) -and -not \( -path 'scripts/external*' -name Pods  \) -print0 | xargs -0 sed -i '' 's/Copyright \(.*\) Google Inc/Copyright \1 the Material Components for iOS authors/'

Added non-source files.

Command run:

grep -Rl 'Copyright .* Google Inc' * --exclude-dir scripts/external --null | xargs -0 sed -i '' 's/Copyright \(.*\) Google Inc/Copyright \1 the Material Components for iOS authors/'

Reviewers: featherless, O1 Material components iOS, randallli

Reviewed By: O1 Material components iOS, randallli

Tags: #material_components_ios

Differential Revision: http://codereview.cc/D1415
2016-08-08 08:16:37 -07:00
..

title layout section excerpt
Collection Layout Attributes detail components Allows passing layout attributes to the cells and supplementary views.

Collection Layout Attributes

Allows passing layout attributes to the cells and supplementary views.

API Documentation


Installation

Requirements

  • Xcode 7.0 or higher.
  • iOS SDK version 7.0 or higher.

Installation with CocoaPods

To add this component to your Xcode project using CocoaPods, add the following to your Podfile:

pod 'MaterialComponents/CollectionLayoutAttributes'

Then, run the following command:

pod install

Usage

Importing

Before using Collection Layout Attributes, you'll need to import it:

Objective-C

#import "MaterialCollectionLayoutAttributes.h"

Swift

import MaterialComponents.MaterialCollectionLayoutAttributes

The MDCCollectionViewLayoutAttributes class allows passing properties to a cell from a collection view layout. Override the -applyLayoutAttributes method of any UICollectionReusableView or UICollectionViewCell subclasses, then apply any of the properties of the attributes class.

Objective-C

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
  [super applyLayoutAttributes:layoutAttributes];
  if ([layoutAttributes isKindOfClass:[MDCCollectionViewLayoutAttributes class]]) {
    MDCCollectionViewLayoutAttributes *attr = (MDCCollectionViewLayoutAttributes *)layoutAttributes;
    if (attr.representedElementCategory == UICollectionElementCategoryCell) {

      // Example to set a background image to the cell background view.
      self.backgroundView = [[UIImageView alloc] initWithImage:attr.backgroundImage];
    }
  }
}

Swift

override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) {
  super.applyLayoutAttributes(layoutAttributes)
  if let attr = layoutAttributes as? MDCCollectionViewLayoutAttributes {
    if (attr.representedElementCategory == .Cell) {

      // Example to set a background image to the cell background view.
      self.backgroundView = UIImageView(image: attr.backgroundImage)
    }
  }
}