UICollectionViewLayoutAttributes クラスをサブクラス化し、いくつかのカスタム プロパティを追加しました。
私のカスタム UICollectionViewLayout クラスでは、静的
+ (Class)layoutAttributesClass
をオーバーライドして、新しい属性クラスを返します。
私の UICollectionViewLayout クラスでは、 をオーバーライドし-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
、値をカスタム プロパティに設定します。
そこで属性クラスを調べると、カスタム プロパティが適切に設定されていることがわかります。
最後に、UICollectionViewCell でこれらのプロパティを取得する必要があるため-(void) applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
、カスタム UICollectionViewLayoutAttributes クラスの値を取得するためにオーバーライドしますが、値は nil です。まるで私がそれらを設定したことがないかのように。
変換などを含め、残りのすべての属性は完全に機能しています。明らかに、私は何か間違ったことをしています。お知らせ下さい。
私のカスタムクラスのHeaderFileが含まれています
@interface UICollectionViewLayoutAttributesWithColor : UICollectionViewLayoutAttributes
@property (strong,nonatomic) UIColor *color;
@end
これが実装です。ご覧のとおり、特別なことは何もありません
@implementation UICollectionViewLayoutAttributesWithColor
@synthesize color=_color;
@end