Text-align-last css property Swift Equivalent

What is the quick equivalent for the css-align-last 'css property? I prefer a closed solution.

Here is what I did and what I get:

enter image description here

The last line (sometimes the only one) is aligned to the left, which is inconvenient.

+5
source share
2 answers

You need to change the label text from Plain to Attributed , then you can insert any line, and alignment, as well as other attributes. Thus, you can use any text style that can be created in a word processor application.

In the following example, I used pages (Mac application) to edit the text format as I needed and copy it to the label text box in Xcode.

enter image description here

Here is an image of a simulator running an application: enter image description here

+3
source

While it is impossible to apply different alignments on one label, if the last (and some only) line should be aligned to the right, why not align the entire label to the right?

enter image description here

EDIT

If this does not fix your problem, I don’t think it can be resolved without code.

In case you decide to write some code, you can study what is the last line of your line (maybe: How to get text from the nth line of UILabel? ) And try to apply other formatting using AttributedString .

If this works, you can always subclass UILabel and override func layoutSubviews() to calculate this automatically for you. That way, you no longer have to think about it!

0
source

Source: https://habr.com/ru/post/1269710/


All Articles