简体   繁体   中英

Delete 3 dots on Truncate Head using UILabel

i need to delete the 3 dots in the head of label, how can i do this?

i already tried others types of line breaks but "Truncate Head" is the only that truncate the label in the beginning.

Here is my actual label with 3 dots '...'

I need to do like this:

Any ideas ?

I don't think there is a good way to do this without faking it. You can fake it by giving the label a trailing constraint but not a leading one. and make the text right justified. This has the effect of anchoring the right side and the text will run off the screen to the left. If you put another view in front of it with the same color as the background, this will mask out the extra text.

This isn't supported out of the box, so you'll need to make a custom label class to accomplish this. See the answer on a similar question "How to change truncate characters in UILabel?"

Instead of setting label.text value, set it as attributed text. Like below.

let attrString = NSAttributedString(string: "YOUR Text")
label.attributedText = attrString

After this, your font settings might be disturbed, which you need to set again programmatically for your label.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM