Home > DeveloperSection > Forums > Inserting Image in UICollectionView in iOS
Eric Martell
Eric Martell

Total Post:9

Points:63
Posted on    November-30-2015 12:27 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 262  View(s)
Rate this:
I am new in application development on iPhone/iPad, so I am getting problem to insert image in collection view.
I check over on internet but not getting correct solution.
Any help would be greatly appreciated.
Thanks in advance.


Tarun Kumar

Total Post:213

Points:1635
Supported
Posted on    November-30-2015 10:49 PM

For displaying Image use cellForItemAtIndexPath: method of UICollectionView.
for example:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UICollectionViewCell *cell = [collectionView
                          dequeueReusableCellWithReuseIdentifier:identifier                                                forIndexPath:indexPath];
    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
    recipeImageView.image = [UIImage imageNamed:[recipeImages
                          objectAtIndex:indexPath.row]];
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage
                                     imageNamed:@"imgName.jpg"]];
    [self.view addSubview:recipeImageView];
    cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage
                          imageNamed:[recipeImages
                          objectAtIndex:indexPath.row]]];
    return cell;
}

Modified On Nov-30-2015 10:51:47 PM

Don't want to miss updates? Please click the below button!

Follow MindStick