text-align-last css property Swift Equivalent

坚强是说给别人听的谎言 提交于 2019-12-12 11:10:35

问题


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.


回答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.

Here is a picture of the simulator running the app:




回答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!



来源:https://stackoverflow.com/questions/45029041/text-align-last-css-property-swift-equivalent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!