Post

Replies

Boosts

Views

Activity

How to make a scrollable multi-line Text
As you can see, I'm really struggling to create a simple multi-line Text. The closest I got so far is putting it in a List instead of a ScrollView, but then I get a line under the text.Any help would be greatly appreciated 🙂/// This was the most obvious approach struct Try1 : View { var body: some View { ScrollView { Text(content) } } } /// OK, I probably need to let it wrap to multiple lines. struct Try2 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) } } } /// Hmm no dice. /// Maybe if I tell it to use the parent's size? struct Try3 : View { var body: some View { ScrollView { Text(content) .relativeWidth(1.0) } } } /// Nope. /// Maybe it needs to be a "fixed" size? struct Try4 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) .fixedSize(horizontal: true, vertical: false) } } } /// The other way? struct Try5 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) .fixedSize(horizontal: false, vertical: true) } } } /// Nope struct Try6 : View { var body: some View { ScrollView { Text(content) .relativeWidth(1.0) }.relativeWidth(1.0) } } /// Still no text wrapping struct Try7 : View { var body: some View { ScrollView { VStack { Text(content) Spacer() } } } } /// This wraps the text correctly, but then draws an unsighly horizontal line right below it :( struct Try8 : View { var body: some View { List { Text(content) .lineLimit(nil) } } }
13
0
16k
Nov ’21
How to make a scrollable multi-line Text
As you can see, I'm really struggling to create a simple multi-line Text. The closest I got so far is putting it in a List instead of a ScrollView, but then I get a line under the text.Any help would be greatly appreciated 🙂/// This was the most obvious approach struct Try1 : View { var body: some View { ScrollView { Text(content) } } } /// OK, I probably need to let it wrap to multiple lines. struct Try2 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) } } } /// Hmm no dice. /// Maybe if I tell it to use the parent's size? struct Try3 : View { var body: some View { ScrollView { Text(content) .relativeWidth(1.0) } } } /// Nope. /// Maybe it needs to be a "fixed" size? struct Try4 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) .fixedSize(horizontal: true, vertical: false) } } } /// The other way? struct Try5 : View { var body: some View { ScrollView { Text(content) .lineLimit(nil) .fixedSize(horizontal: false, vertical: true) } } } /// Nope struct Try6 : View { var body: some View { ScrollView { Text(content) .relativeWidth(1.0) }.relativeWidth(1.0) } } /// Still no text wrapping struct Try7 : View { var body: some View { ScrollView { VStack { Text(content) Spacer() } } } } /// This wraps the text correctly, but then draws an unsighly horizontal line right below it :( struct Try8 : View { var body: some View { List { Text(content) .lineLimit(nil) } } }
Replies
13
Boosts
0
Views
16k
Activity
Nov ’21