I have a NSMutableParagraphStyle style that I apply to a NSMutableAttributedString:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myString = "Before a telephone call, I need to go to the bathroom..."
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.byWordWrapping
let myMutableString = NSMutableAttributedString(
string: myString,
attributes: [
NSFontAttributeName:UIFont(
name: "Georgia",
size: 45.0
)!,
NSParagraphStyleAttributeName: paragraphStyle
]
)
let textView = UITextView( frame: CGRect(
x: 20,
y: 25,
width: 260,
height: 400
) )
textView.attributedText = myMutableString
self.view.addSubview( textView )
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
But when I add that mutable string to a UITextView, it keeps breaking the words.
The word break does not appear at the same place when I go for paragraphStyle.lineBreakMode = NSLineBreakMode.byCharWrapping
... So it does have an effect. But this is still partial. I have the word «call» that breaks after the «c», this is super weird.
And it is something I can reproduce in a storyboard editor :
Aaaaaannnnddd the solution was to try editing my code in sublime text and realise that there is a non breakable space between telephone and call.
It seems a so stupidly basic functionality. Why can't Xcode tell me that...