UICollectionview set cell height based on image height

Nisha

Hii i want set height of UICollectionView cell based on image i get from url. can any one help me? i have checked some libraries in that they have given random height to cell. In this one random height given to cell. when i try to give image height like this it is giving result. space is coming between cells.

and also tried like this but not working space is coming between cell rows. see this

Tanvi Jain
    Write in ViewDidLoad Method

    for (int i=0; i<[imageURLArray count]; i++)
        {
             //Declare Globally
            IMGArray1=[[NSMutableArray alloc] init];

            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[imageURLArray objectAtIndex:i]]];
            NSOperationQueue *urlQue = [[NSOperationQueue alloc] init];
            [NSURLConnection sendAsynchronousRequest:urlRequest queue:urlQue completionHandler:^(NSURLResponse *response,
                                                                                                 NSData *MoblieDatadata, NSError *error)
             {
                 if ([MoblieDatadata length] >0 && error == nil)
                 {
                     UIImage *image = [[UIImage alloc]initWithData:MoblieDatadata];
                     [IMGArray1 addObject:image];

                 }
                 else if ([MoblieDatadata length] == 0 && error == nil)
                 {

                     NSLog(@"Nothing was downloaded.");



                 }
                 else if (error != nil)
                 {
                     NSLog(@"Error happened = %@", error);
                     dispatch_async(dispatch_get_main_queue(), ^{


                     });
                 }
             }];


    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                     cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        examplemycell *myCell = [collectionView
                                        dequeueReusableCellWithReuseIdentifier:@"cell"
                                        forIndexPath:indexPath];

        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        myCell.imageView.image = image;

        return myCell;
    }
    #pragma mark -
    #pragma mark UICollectionViewFlowLayoutDelegate

    -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UIImage *image;
        int row = [indexPath row];

        image = [UIImage imageNamed:IMGArray1[row]];

        return image.size;
    }

//For setting spacing between collectionview cells
//use the delegate method like

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionView *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section  
  {
    return 10; // This is the minimum inter item spacing, can be more
  }

And Use this for verticle line spacing between cells

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UICollectionView - dynamic cell height?

From Dev

Set height of UITableViewCell by height of UICollectionView

From Dev

Cell Row Height based on Image size

From Dev

Set height based on width

From Dev

Set height based on width

From Dev

Set image slider height to the height of the smallest image

From Dev

If no Image, change row cell height

From Dev

If no Image, change row cell height

From Dev

Cell height equal to image width

From Dev

resize table height automatically based on image height?

From Dev

How to get div height based on image height?

From Dev

Set height of div equal to height of image

From Dev

Set height of div equal to height of image

From Dev

Set height of container class to height of image

From Dev

Set image to UICollectionView Cell on tap

From Dev

how to set image width height based on screen size in gridview

From Dev

how to set image width height based on screen size in gridview

From Dev

Adjust cell height to image cell height within WPF DataGrid

From Dev

Resize image based on text height

From Dev

Set Image width and height at runtime

From Dev

Set image width and height with jquery

From Dev

Set height of UITableView which contain dynamic Cell Height

From Dev

Updating cell height after image downloads

From Dev

Calculate Cell height on basis of label text + image

From Dev

Why image not fit to table cell height in html?

From Dev

Image causing table cell height to extend

From Dev

UICollectionView with dynamic height not getting same space between cell

From Dev

Unable to set the height of a prototype cell as a constraint in storyboard

From Dev

How to set table border less then cell height

Related Related

HotTag

Archive