SpreadsheetView
SpreadsheetView copied to clipboard
Height of cell depends on the content
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
Can I expand the height of that particular cell and the other cell still the same height?
Thank you in advance!
I'm in the same situation in here ! @devaileen have you found a solution for this ? tks!
@devaileen @saormart Not yet supported self-sizing cell. You should calculate/assume maximum width/height each cells.
@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 good question!
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
}