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:
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.
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?
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!
0 comments:
Post a Comment