1

I have a SwiftUI view which is an HStack of two views: 1. A simple Text view, which acts as sort of a label, and is always a single line 2. A custom UIKit view which is a UITextView with lots of custom formatting

My desire is to restrict the height of the UITextView to match the height of the Text view (single line, height dependent on system fonts, etc). I've tried many ways to go about this, but I can't seem to find something that works. GeometryReader seems to only pass parent attributes to child, but doesn't solve the "sibling" issue.

Any ideas or insight?

1
  • 1
    can you please paste your code ? Commented Apr 23, 2020 at 6:46

1 Answer 1

1

Here is a demo of possible layout. Tested with Xcode 11.4 / iSO 13.4

demo

Note: .border and .padding are added just for demo & better visibility. Important places are marked in comment. MultilineTextView is a simple representable of UITextView

struct DemoFixedToLabel: View {
    var body: some View {
        HStack {
            Text("Some Text").font(Font.system(.title))
                .padding()
                .border(Color.blue)
                .fixedSize()             // << here !!
            MultilineTextView(text: .constant("My desire is to restrict the height of the UITextView to match the height of the Text"))
                .border(Color.green)
        }
        .padding()
        .border(Color.red)
        .fixedSize(horizontal: false, vertical: true)    // << here !!
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.