Thursday, July 20, 2017

text-align-last css property Swift Equivalent

Leave a Comment

What is the swift Equivalent for 'text-align-last' css property? I prefer a codeless solution.

Here is what i have done and what i get:

enter image description here

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

2 Answers

Answers 1

You need to change the label's text from Plain to Attributed, then you can paste any string and the alignment, as well as other attributes, will hold. So basically any text style that can create on word processor application can be used here.

In the following example I've used pages (Mac application) to edit the text format as I liked and copied it to the label text box in Xcode.

enter image description here

Here is a picture of the simulator running the app: enter image description here

Answers 2

While it is not possible to apply different aligns on a single label, if the last(and sometime only) line should be aligned to the right why not align the entire label to the right?

enter image description here

EDIT

If that doesn't fix you problem then I don't think it's possible to resolve without code.

In the case you do decide to write some code you could look into determining which is the last line of your string (maybe: How to get text from nth line of UILabel? ) and try to apply different formatting with AttributedString.

If that works then you can always subclass UILabel and override func layoutSubviews() to calculate this automatically for you. This way you won't have to think about it again!

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment