In UIKit it was relatively easy to calculate the needed size of a string with a given Font. How can I achieve this in SwiftUI? It seems hat the needed properties on Text and Font are missing to convert objects to SwiftUI and do the calculation here.
Here is the code I have so far: Problem: I don't want to use a hard coded Font (and not UIFont at all).
private func determineTruncation(_ geometry: GeometryProxy) {
// Calculate the bounding box we'd need to render the
// text given the width from the GeometryReader.
let total = text.boundingRect(
with: CGSize(
width: geometry.size.width,
height: .greatestFiniteMagnitude
),
options: .usesLineFragmentOrigin,
attributes: [.font: UIFont.systemFont(ofSize: 16)],
context: nil
)
if total.size.height > geometry.size.height {
self.truncated = true
}
}