Swift's UILabel provides a property called lineBreakMode to specify wrapping and abbreviation. Among the modes that can be specified, there are byWordWrapping that separates the wrapping position by words and byCharWrapping that separates characters, but even if byWordWrapping is specified, Japanese sentences are not displayed by word separation. Then, I was wondering if there is any difference between specifying byCharWrapping and byWordWrapping, so I checked it.
Xcode Version 12.0 Swift 5.3
byCharWrapping When I specified byCharWrapping for lineBreakMode and displayed it, it looks like the image. The background of UILabel is yellow for clarity.
byWordWrapping Next, I specified byWordWrapping to display the same sentence. If you specify byWordWrapping, it seems to be adjusted so that punctuation marks, the end of parentheses, lowercase letters, stretch bars, etc. do not appear at the beginning of the line. This is easier to read.
If you can specify either byCharWrapping or byWordWrapping, it seems better to use byWordWrapping, which takes kinsoku rules into consideration.
■ Reference site https://developer.apple.com/documentation/uikit/nslinebreakmode
Recommended Posts