diff --git a/ios/CellContentStyle.swift b/ios/CellContentStyle.swift index 9cdbebf0..8fc50163 100644 --- a/ios/CellContentStyle.swift +++ b/ios/CellContentStyle.swift @@ -12,4 +12,5 @@ struct CellContentStyle: Decodable { var color: String? var fontFamily: String? var fontSize: Int? + var rowHeight: Int? } diff --git a/ios/DataCellView.swift b/ios/DataCellView.swift index 9fbc6ccd..f29eb0eb 100644 --- a/ios/DataCellView.swift +++ b/ios/DataCellView.swift @@ -13,6 +13,7 @@ class DataCellView: UICollectionViewCell { var borderColor = UIColor.black.withAlphaComponent(0.1) var selectionsEngine: SelectionsEngine? var cellColor: UIColor? + var numberOfLines = 1; static let minWidth: CGFloat = 40 override init(frame: CGRect) { @@ -34,7 +35,7 @@ class DataCellView: UICollectionViewCell { let col = cols[index] if let label = views[index] as? PaddedLabel { - let newFrame = CGRect(x: x, y: 0, width: Int(col.width!), height: theme.rowHeight!) + let newFrame = CGRect(x: x, y: 0, width: Int(col.width!), height: theme.rowHeight! * numberOfLines) label.textAlignment = element.qNum == nil ? .left : .right x += Int(col.width!) label.frame = newFrame.integral @@ -44,7 +45,7 @@ class DataCellView: UICollectionViewCell { label.cell = element label.checkSelected(selectionsEngine) label.textColor = cellColor! - + label.numberOfLines = numberOfLines } } } diff --git a/ios/DataCollectionView.swift b/ios/DataCollectionView.swift index 5155d0e4..d194fc3f 100644 --- a/ios/DataCollectionView.swift +++ b/ios/DataCollectionView.swift @@ -23,12 +23,14 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe var selectionsEngine: SelectionsEngine? let reuseIdentifier = "CellIdentifier" var cellColor = UIColor.black + var cellStyle = CellContentStyle() init(frame: CGRect, withRows rows: [DataRow], andColumns cols: [DataColumn], theme: TableTheme, selectionsEngine: SelectionsEngine, cellStyle: CellContentStyle) { super.init(frame: frame) self.tableTheme = theme self.selectionsEngine = selectionsEngine let colorParser = ColorParser() + self.cellStyle = cellStyle if let colorString = cellStyle.color { cellColor = colorParser.fromCSS(cssString: colorString) } @@ -129,6 +131,7 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe cell.backgroundColor = indexPath.row % 2 == 0 ? .white : UIColor(red: 0.97, green: 0.97, blue: 0.97, alpha: 1.0) cell.cellColor = cellColor + cell.numberOfLines = cellStyle.rowHeight ?? 1 if let data = dataRows { let dataRow = data[indexPath.row] cell.selectionsEngine = self.selectionsEngine @@ -143,7 +146,8 @@ class DataCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDe func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let width = dataColumns?.reduce(0, {$0 + $1.width!}) ?? frame.width - return CGSize(width: width, height: CGFloat(tableTheme!.rowHeight!)) + let height = cellStyle.rowHeight ?? 1 + return CGSize(width: width, height: CGFloat(tableTheme!.rowHeight! * height)) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { diff --git a/ios/PaddedLabel.swift b/ios/PaddedLabel.swift index f1c5b68a..c6580ad9 100644 --- a/ios/PaddedLabel.swift +++ b/ios/PaddedLabel.swift @@ -26,26 +26,31 @@ class PaddedLabel: UILabel, SelectionsListener { fatalError("init(coder:) has not been implemented") } - override var intrinsicContentSize: CGSize { - numberOfLines = 0 // don't forget! - var s = super.intrinsicContentSize - s.height += UIEI.top + UIEI.bottom - s.width += UIEI.left + UIEI.right - return s - } +// override var intrinsicContentSize: CGSize { +// numberOfLines = 0 // don't forget! +// var s = super.intrinsicContentSize +// s.height += UIEI.top + UIEI.bottom +// s.width += UIEI.left + UIEI.right +// return s +// } override func drawText(in rect: CGRect) { - let r = rect.inset(by: UIEI) - super.drawText(in: r) + if(numberOfLines != 1) { + let r = self.textRect(forBounds: rect.inset(by: UIEI), limitedToNumberOfLines: self.numberOfLines) + super.drawText(in: r) + } else { + let r = rect.inset(by: UIEI) + super.drawText(in: r) + } } override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines n: Int) -> CGRect { - let b = bounds - let tr = b.inset(by: UIEI) - let ctr = super.textRect(forBounds: tr, limitedToNumberOfLines: 0) - // that line of code MUST be LAST in this function, NOT first - return ctr + + let ctr = super.textRect(forBounds: bounds, limitedToNumberOfLines: n) + let xOffset = self.textAlignment == .left ? PaddedLabel.PaddingSize : -PaddedLabel.PaddingSize + return CGRect(x: ctr.origin.x + CGFloat(xOffset), y: ctr.origin.y + 8, width: ctr.size.width, height: ctr.size.height) + } func makeSelectable(selectionsEngine: SelectionsEngine) {