I am using SSToolkit/SSCollectionView and I have a custom SSCollectionViewItem but I am having a hard time getting the frame size for that view which was set by the SSCollectionView Delegate:
- (CGSize)collectionView:(SSCollectionView *)aCollectionView itemSizeForSection:(NSUInteger)section {
return CGSizeMake(280.0f, 280.0f);
}
Here is the item being initalizes:
#pragma mark - Initializer
- (id)initWithReuseIdentifier:(NSString *)aReuseIdentifier {
if ((self = [super initWithStyle:SSCollectionViewItemStyleImage reuseIdentifier:aReuseIdentifier])) {
if([aReuseIdentifier isEqualToString:@"featuredIdentifier"]) {
NSLog(@"Frame: %f", self.frame.size.width);
return self;
} else {
self.imageView.backgroundColor = [UIColor colorWithWhite:0.95f alpha:1.0f];
return self;
}
self.imageView.backgroundColor = [UIColor colorWithWhite:0.95f alpha:1.0f];
}
return self;
}
NSLog(@"FRAME Width:%f", self.frame.size.width); always returns a 0
This is the expected behavior. All collection view items are always initialized with CGRectZero since they could be reused in a section with different item sizes.
SSCollectionView automatically sizes the items right before they are displayed. You should implement
layoutSubviewsif you need to do layout based on the item’s size.Also, it looks like you are trying to do different drawing based on the identifier. I highly recommend you make a different class for each identifier to keep things clean and understandable.