G
G
Gleb2021-10-28 14:12:41
Swift
Gleb, 2021-10-28 14:12:41

How to remove delimiter between words when moving to a new line?

617a847bc20c3319112142.jpeg
The problem is to remove the dot if the words are wrapped to a new line.

let anotherInfo = info
            .compactMap { $0 }
            .filter { !$0.isEmpty }
            .joined(separator: " · ")
            .with(color: .okkoLightWhiteText)
        
        let result = NSMutableAttributedString()
        if rating.length > 0 {
            result += rating
            result += value.displayInfo.rating.count >= 3 ? "\n" : "  "
        }
        result += anotherInfo
        
        return .init(text: result, style: .regularText, numberOfLines: 0)


my idea was to do
if anotherInfo.length.words > n {
         ...
         }
        print("\(anotherInfo)")


but anotherInfo is a single string made up of words from an array of strings - info.
I can't figure out how to remove the division then. The dot is centered as it appears at the beginning of a new line or at the end of the previous one. Mb it is possible to create a certain rule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2021-10-28
@shevzoom

And you try your application on a device with a different screen resolution .... Your transfer will be in a different place ....
Conclusion - count the width of the letters, the width of the element, the number of letters that fit into one line, and delete the dot that is not needed .
.... or - immediately divide the text into two lines, concatenating them then through the line break character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question