2014-12-11 5 views
0

Я довольно новичок в IOS Development.I используя код из этого урока Creating a Paged Photo Gallery With a UICollectionView. Вы можете получить код из этого link. Здесь я хочу изменить верхнее и нижнее расстояние изображения в ячейке коллекции. Как я могу это сделать? Вот код для просмотра коллекции ячейки:UICollectionView изменение верхнего и нижнего ячеек ячейки

-(void)setupCollectionView { 
    [self.collectionView registerClass:[CMFGalleryCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; 

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 
    [flowLayout setMinimumInteritemSpacing:0.0f]; 
    [flowLayout setMinimumLineSpacing:0.0f]; 
    [self.collectionView setPagingEnabled:YES]; 
    [self.collectionView setCollectionViewLayout:flowLayout]; 
} 


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    return 1; 
} 

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return [self.dataArray count]; 
} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    CMFGalleryCell *cell = (CMFGalleryCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; 

    NSString *imageName = [self.dataArray objectAtIndex:indexPath.row]; 
    [cell setImageName:imageName]; 
    [cell updateCell]; 

    return cell; 

} 

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 
    return self.collectionView.frame.size; 
} 


#pragma mark - 
#pragma mark Data methods 
-(void)loadImages { 

    NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Assets"]; 
    self.dataArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:sourcePath error:NULL]; 

} 

Код для CMFGallary.cell является:

#import "CMFGalleryCell.h" 

@interface CMFGalleryCell() 
@property (strong, nonatomic) IBOutlet UIImageView *imageView; 
@end 

@implementation CMFGalleryCell 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CMFGalleryCell" owner:self options:nil]; 

     if ([arrayOfViews count] < 1) { 
      return nil; 
     } 

     if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) { 
      return nil; 
     } 

     self = [arrayOfViews objectAtIndex:0]; 
    } 

    return self; 
} 

-(void)updateCell { 

    NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Assets"]; 
    NSString *filename = [NSString stringWithFormat:@"%@/%@", sourcePath, self.imageName]; 

    UIImage *image = [UIImage imageWithContentsOfFile:filename]; 

    [self.imageView setImage:image]; 

    [self.imageView setContentMode:UIViewContentModeScaleAspectFit]; 

} 

@end 
+0

Пожалуйста, включите соответствующий код непосредственно в вопрос. Ссылки могут стать недействительными, если связанная страница изменится. – honk

+0

Можете ли вы скопировать/вставить код в CMFGalleryCell.m? – Kujey

+0

вы можете увидеть его выше ... –

ответ

0

Обновить макет потока вид коллекции для добавления врезки, как:

UICollectionViewFlowLayout *flow = yourCollectionView.collectionViewLayout; 
flow.sectionInset = UIEdgeInsetsMake(topMargin, leftMargin, bottom, right); 

или Внедрение

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView 
         layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ 
    return UIEdgeInsetsMake(topMargin, leftMargin, bottom, right); 
} 
+0

Нет, он не меняет камеру с изображениями коллекции ... пожалуйста, помогите –

Смежные вопросы