У меня есть UICollectionViewCellМалый UIImage вид в обычае UICollectionViewCell
#import "DBPhotoCollectionViewCell.h"
#define IMAGEVIEW_BORDER_LENGTH 5
@implementation DBPhotoCollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
/* Need to implement the initWithCoder method since this class will be created from the storyboard */
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self){
[self setup];
}
return self;
}
/* Create the UIImageView and add it to the cell's contentView in code. */
-(void)setup
{
self.imageView = [[UIImageView alloc] initWithFrame:CGRectInset(self.bounds, IMAGEVIEW_BORDER_LENGTH, IMAGEVIEW_BORDER_LENGTH)];
[self.contentView addSubview:self.imageView];
}
@end
И называют эту ячейку из CollectionViewController класса
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Photo Cell";
DBPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
cell.imageView.image = [UIImage imageNamed:@"Astronaut.jpg"];
// Configure the cell
return cell;
}
Но у меня есть одна проблема, когда я начинаю мое заявление моя картина показала с малым размером , Что я пропустил?
http://screencast.com/t/ia8tE05P6yc http://screencast.com/t/33N4AhT7
Что делает возвращение self.bounds? Я думаю, что это будет размер ячейки по умолчанию (50 x 50), когда вы проверяете это в методе init. – rdelmar
Я ручной размер ячейки ячейки в main.storyboard 155 x 155. Думаю, я пропустил также установить размер ячейки в настройках Collection View. Я открыл раскадровку в качестве исходного кода и нашел место, где должно быть 155 х 155. – Dens