OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHROME
_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHROME
_H_ |
| 7 |
| 8 #import <CoreGraphics/CoreGraphics.h> |
| 9 |
| 10 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 11 |
| 12 @class CollectionViewItem; |
| 13 |
| 14 // Augments MDCCollectionViewCell for use in conjunction with |
| 15 // CollectionViewItem. |
| 16 @interface MDCCollectionViewCell (Chrome) |
| 17 |
| 18 // Returns the height this class of cell would need to be to fit within |
| 19 // |targetWidth|, configured by |item|. The returned height is calculated by |
| 20 // Auto Layout so that the contents of the cell could fit within the |
| 21 // |targetWidth|. |
| 22 // If the cell contains multi-line labels, make sure to update the |
| 23 // |preferredMaxLayoutWidth| in -layoutSubviews like so: |
| 24 // |
| 25 // @implementation MyCell |
| 26 // |
| 27 // - (void)layoutSubView { |
| 28 // [super layoutSubviews]; |
| 29 // |
| 30 // // Adjust the text label preferredMaxLayoutWidth when the parent's width |
| 31 // // changes, for instance on screen rotation. |
| 32 // CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
| 33 // _textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding; |
| 34 // |
| 35 // // Re-layout with the new preferred width to allow the label to adjust its |
| 36 // // height. |
| 37 // [super layoutSubviews]; |
| 38 // } |
| 39 // |
| 40 // @end |
| 41 + (CGFloat)cr_preferredHeightForWidth:(CGFloat)targetWidth |
| 42 forItem:(CollectionViewItem*)item; |
| 43 |
| 44 @end |
| 45 |
| 46 #endif // IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHR
OME_H_ |
OLD | NEW |