if you know the image path or name then you may implement something like this.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [[UICollectionViewCell alloc]initWithFrame:CGRectMake(0, 0, 50.0, 50.0)];
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50.0, 50.0)];
[imageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"your photo name here" ofType:@"png"]]];//if Path is from main bundle
//else
// documentDirectory URL as
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:fileName];
[imageView setImage:[UIImage imageWithContentsOfFile:filePath];
}
[cell setBackgroundView:imageView];
NSLog(@"%@",cell);
NSLog(@"Index Path = %ld",(long)indexPath.row);
return cell;
}
you also need to set delegate and datasource
of UICollectionView
as
[yourCollectionViewObject setDelegate:self];// if you need to use didselect or like...
[yourCollectionViewObject setDataSource:self];
and another required datasource method for returning count...
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return count;
}