Created
October 16, 2024 18:34
-
-
Save aheze/44761be4e999ce2e20596f5cfd9cd0c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Text("Hello, world!") | |
.frame(maxWidth: .infinity, maxHeight: .infinity) | |
ResizableTextView() | |
.border(.red) | |
} | |
.padding() | |
} | |
} | |
// this doesn't work when the text is wrapped | |
struct ResizableTextView: UIViewRepresentable { | |
func makeUIView(context: Context) -> UITextView { | |
let textView = UITextView() | |
textView.font = UIFont.preferredFont(forTextStyle: .title1) | |
// fit content | |
textView.isScrollEnabled = false | |
textView.setContentHuggingPriority(.defaultHigh, for: .vertical) | |
// prevent expanding horizontally | |
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | |
return textView | |
} | |
func updateUIView(_ uiView: UITextView, context: Context) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment