SpreadsheetView icon indicating copy to clipboard operation
SpreadsheetView copied to clipboard

Height of cell depends on the content

Open aileenromero opened this issue 6 years ago • 5 comments

Is there a way we dynamically change the height of cell depending on the contents inside it?

For example the data after Extracurricular Activity after Drama Club just as what you see in the photo simulator screen shot - iphone 5s - 2018-06-21 at 11 59 40

Can I expand the height of that particular cell and the other cell still the same height?

Thank you in advance!

aileenromero avatar Jun 21 '18 04:06 aileenromero

I'm in the same situation in here ! @devaileen have you found a solution for this ? tks!

saormart avatar Jun 25 '18 14:06 saormart

@devaileen @saormart Not yet supported self-sizing cell. You should calculate/assume maximum width/height each cells.

kishikawakatsumi avatar Jun 26 '18 17:06 kishikawakatsumi

@kishikawakatsumi how can i calculate and set height for each cell dynamically based on its content can you provide an example please i have tried following code let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: ValueCell.self), for: indexPath) as! ValueCell cell.label.text = labelValues[indexPath.row] if labelValues[indexPath.row].count > 28{ cell.bounds = CGRect.init(x: 0, y: 0, width: (UIScreen.main.bounds.width-32)/2, height: 100) } in the function func spreadsheetView(_ spreadsheetView: SpreadsheetView, cellForItemAt indexPath: IndexPath) -> Cell? { but no luck

hamzashahid91 avatar Jul 24 '18 06:07 hamzashahid91

@hamzashahid91 good question!

saormart avatar Aug 06 '18 21:08 saormart

I got around it by making a label for each column in the row, figuring out its size and then determining the maximum height needed. I'm using headers, thus row 0 has a standard value. Its a little data intensive, but works.

func spreadsheetView(_ spreadsheetView: SpreadsheetView, heightForRow row: Int) -> CGFloat {
   if row == 0 {
     return 40
   }
   var maxHeight : CGFloat = 40.0
   for column in mData[row-1] {
     let label = UILabel()
     label.lineBreakMode = .byWordWrapping
     let maxRect = CGRect(x: 0, y: 0, width: 120, height: 500)
     label.text = column
     let rect = label.textRect(forBounds: maxRect, limitedToNumberOfLines: 0)
     maxHeight = max(maxHeight, rect.height)
   }
   return maxHeight
 }

lucasholzen avatar Dec 19 '18 23:12 lucasholzen