I'm trying to wrap a custom subclass of UILabel
in UIViewRepresentable
to use it in SwiftUI. I'm using .sizeToFit
and printing the frame, and it looks right while it's in the wrapper:
func makeUIView(context: Context) -> CustomUILabel {
let view = CustomUILabel()
view.customProperty = model.customProperty
view.sizeToFit()
print(model.latex,view.frame.size) // this prints the correct size, how to propagate?
return view
}
but when I run this in a VStack
, it draws the UIViewRepresentable
with the maximum space possible.
var body: some View {
GeometryReader{ geometry in
VStack(spacing: 0){
Rectangle()
.fill(Color.red)
.frame( height: geometry.size.height/2 - 5 + self.draggedOffset.height)
Rectangle()
.fill(Color.orange)
.frame(height: 10)
custonView(model:self.model)
Spacer()
}
}
Is there a way to propagate the size of the UIView
to its parent, similar to how you use preference keys on a native SwiftUI
view?