If you want the text within a UITextView to be hyphenated (instead of inappropriately stretched in places when justified), forget NSParagraphStyle and its mutable partner, NSMutableParagraphStyle. At least this is what I've found transforming HTML into attributed text. I can set the hyphenation factor to zero for the paragraph style and the layout manager for the UITextView will override it. See here an example where a HTML file is held within the Assets folder. if let asset = NSDataAsset(name: "\(assetName)") { let data = asset.data let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.hyphenationFactor = 0.0 var dict:NSDictionary? = NSDictionary(dictionary: [NSAttributedString.Key.paragraphStyle : paragraphStyle]) do { let attr = try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: &dict) textView.layout
Technology tips for writers, editors, designers, illustrators, programmers and publishers, and now Retro Gamers.