// // ViewController.swift // HyphenationBug // // Created by Ivan Barabanshchykov on 22.12.2021. // import UIKit class ViewController: UIViewController { var label = UILabel() var textView = UITextView() var textView2 = UITextView() override func viewDidLoad() { super.viewDidLoad() [label, textView, textView2].forEach { view.addSubview($0) } // Correct hyphenation in German will be: "Pu-bli-****-lieb-lin-ge". // If iOS will use English hyphenation rules on this German word hyphenation will be: "Pub–likum–slieblinge". // And in our case it mixes both on iOS 15: "Pu-b–li-***–s-lieb-lin-ge".. // String with custom soft hyphens placed. let text = "Pu\u{00AD}bli\u{00AD}****\u{00AD}lieb\u{00AD}lin\u{00AD}ge" let textWithNoHyphens = "Publikumslieblinge" let paragraph = NSMutableParagraphStyle() if #available(iOS 15.0, *) { paragraph.usesDefaultHyphenation = false } else { paragraph.hyphenationFactor = 0 } let attributedText = NSMutableAttributedString(string: text, attributes: [NSAttributedString.Key.paragraphStyle : paragraph]) // First simple Label, if there is unicode hyphen symbol inside string u{00AD} on iOS 15 hyphenation is wrong. In previous iOS 14 our custom hyphenation was working correct, seems on iOS 15 it also adds automatic hyphens in places for default devices language (we have multilanguage app here, there could be several languages on one screen, so it bugs us a lot). label.text = text // label.text = textWithNoHyphens label.font = UIFont.systemFont(ofSize: 50) label.numberOfLines = 0 label.frame = CGRect(x: 20, y: 50, width: 240, height: 200) textView.frame = CGRect(x: 20, y: 250, width: 240, height: 200) // First simple TextView with switched off DefaultHyphenation textView.isEditable = false textView.isScrollEnabled = false textView.text = text textView.font = UIFont.systemFont(ofSize: 50) textView.textContainerInset = .init(top: 0, left: -5, bottom: 0, right: -5) textView.layoutManager.usesDefaultHyphenation = false // Second TextView with attributed string with switched off DefaultHyphenation in attributed string textView2.frame = CGRect(x: 20, y: 450, width: 240, height: 200) textView2.isEditable = false textView2.isScrollEnabled = false textView2.attributedText = attributedText textView2.font = UIFont.systemFont(ofSize: 50) textView2.textContainerInset = .init(top: 0, left: -5, bottom: 0, right: -5) // textView2.layoutManager.delegate = self } } extension ViewController: NSLayoutManagerDelegate { }