In iOS 15, Soft hyphen is not working properly when using unicode character in UILabel

1.6k views Asked by At

In iOS 15 soft hyphens (\u{00AD}) are not considered when setting text on UILabel. for example: The following code does render the text with the soft hyphen correctly in iOS 13 & 14, but not in iOS 15.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    label.text = "Very\u{00AD}VeryVeryVeryVeryVeryLongWordWithASoftHyphenTo"
  }
}

Result: enter image description here

How can i make UILabel consider the soft hyphen (\u{00AD}) in iOS 15?

1

There are 1 answers

1
Ivan Barabanshchykov On BEST ANSWER

Got response from Apple for this one:

Before iOS 15, we strictly followed soft hyphen, while in iOS 15 we now only consider those as hyphenation opportunities.

That is the design, and there are no plans to change it. The app should be able to use languageIdentifier attribute to influence the hyphenation with the attributed string so that it should follow German hyphenation even when system language is English.

https://developer.apple.com/documentation/foundation/attributescopes/foundationattributes/3802173-languageidentifier

So basically now we should use languageIdentifier attribute, lesser opportunities for our own custom hyphenation rules (like remove ugly, one side short, hyphenation break), but works grammatically correctly.

Soft hyphens still working but just as an addition.