If I have a string that I am going to load into a TextField how can I make a line break \n occur every 10 characters (including spaces and whatnot) but not go to the next line mid-word... Like wrap the text with a max of 10 characters? But I'm not just wrapping in a UITextField I actually need the \n's entered because it will be used in something else as well... (This is for iOS if that matters) any help is appreciated I'm really stuck!
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
I created something that actually does the breaks, not at every 10 chars, but between words, not there is no hyphenation engine there, that would require a dictionary. I built it off of Perceptions answer.
I'd do it in a way something like that:
I believe that something like that should work. I don't have a Mac nearby, so I wrote that down by my memory(which isn't always flawless). So there might be a few errors in the code.
Hope it helps
You might want to make use of NSScanner in a loop to put together this kind of thing, but to figure out the precise algorithm you'd need to clarify exactly how you want it to work. Here are questions that you would need to answer:
With these assumptions about your problem in mind, I would code it like this:
You will have to insert the newline characters into your string yourself, there isn't a built-in function for this afaik.