-1

I have a UICollectionView cell, which has multiple itemsenter image description here


I need to implement its dynamic height depending on the data of 1st bold label I have tried multiple code snippets but not working for my case. as most of them are checking a specific label height and assigning it to the cell size.. Thanks

Majid Bashir
  • 558
  • 1
  • 4
  • 27

1 Answers1

0

I have written this function in Xamarin.iOS to calculate the height of cell. Hope this will help you.

CGRect GetRectOfItemNameLabel(ActivityTaskModel item , UITableView tableView)
        {
            nfloat width = tableView.Frame.Width;
            UIStringAttributes attrs1 = new UIStringAttributes ();
            attrs1.Font = UIFont.FromName("Helvetica", 17);
            CGRect frameName = ((NSString)item.TaskDescription).GetBoundingRect (new CGSize (width, 100000), NSStringDrawingOptions.UsesLineFragmentOrigin, attrs1, null);
            return frameName;
    }   

Make sure you don't provide any height constraint to that label/TextView.

Note : If your text is larger then rather than using Label use TextView

PrafulD
  • 548
  • 5
  • 13