It's a pretty trivial question I know, but I have to be able to justify-align the text in a text view using swift. It is an already existing text view on the storyboard which has been hooked up to an outlet, let's call it justifyTextView
.
Can anybody give some code for this? I can't seem to find anything online about it.
To align a text view along the horizontal axis, you need to use . frame() modifier with maxWidth set to . infinity and alignment to the alignment you want.
When SwiftUI's Text views wrap across multiple lines, they align to their leading edge by default. If you want to change that, use the multilineTextAlignment() modifier to specify an alternative, such as . center , or . trailing .
justified—text is aligned along the left margin, with letter-spacing and word-spacing adjusted so that the text falls flush with both margins, also known as fully justified or full justification; centered—text is aligned to neither the left nor right margin; there is an even gap on each side of each line.
label.textAlignment = NSTextAlignment.Justified
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With