INSERTING IMAGE IN UICOLLECTIONVIEW IN IOS

Eric Martell

Total Post:9

Points:63
Posted by  Eric Martell
 548  View(s)
Ratings:
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.
  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Inserting Image in UICollectionView in iOS

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!