简体   繁体   English

如何仅在特定的分隔符上实现UILabel换行符?

[英]How to achieve UILabel line breaks only on a specific separator character?

I have a string which has a separator character between words (Words with spaces) eg. 我有一个字符串,在单词(带空格的单词)之间具有分隔符。

"Male • 89 • Senior Citizen • Side Lower Berth • Non Veg • Bedroll"

So "•" is separator here. 因此,“•”是分隔符。 Now while assigning it to a multiline label I want line breaks only on this separator. 现在,在将其分配给多行标签时,我只希望在此分隔符上换行。 Eg. 例如。 I don't want line breaks in between "Side Lower Berth" so that some part of it rendered in the first line and remaining one in next line. 我不希望在“ Side Lower Berth”之间插入换行符,以使它的某些部分在第一行中呈现,而在下一行中保留。 It should draw it next line only by making the decision based on the defined separator "•" here. 仅应根据此处定义的分隔符“•”做出决定,才可以绘制下一行。

在此处输入图片说明

Try replacing all of your ordinary spaces with nonbreaking spaces, except in the places where you want to allow that break the line. 尝试用不间断空格替换所有普通空格,但在您希望允许该行换行的地方除外。 (So leave an ordinary space after each bullet) (因此,在每个子弹后留一个普通的空格)

What if you jump lines when • appears? 如果出现•时跳线怎么办? If you wanna try : 如果您想尝试:

yourString.replacingOccurrences(of: "•", with: "\n")

I don't know if that's what you want, if not, sorry. 我不知道那是不是你想要的,如果不是,对不起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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