kidsid49
kidsid49

Reputation: 1378

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. It should draw it next line only by making the decision based on the defined separator "•" here.

enter image description here

Upvotes: 1

Views: 193

Answers (2)

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.

Upvotes: 1

Duncan C
Duncan C

Reputation: 131418

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)

Upvotes: 1

Related Questions