Skip to content

Instantly share code, notes, and snippets.

@kiding
Last active April 21, 2021 06:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiding/8dccd25b536ebb510dcec5be57c48f6f to your computer and use it in GitHub Desktop.
Save kiding/8dccd25b536ebb510dcec5be57c48f6f to your computer and use it in GitHub Desktop.
word-break: keep-all; but in Swift
import UIKit
class KRLayoutManagerDelegate: NSObject, NSLayoutManagerDelegate {
func layoutManager(_ layoutManager: NSLayoutManager,
shouldBreakLineByWordBeforeCharacterAt charIndex: Int) -> Bool {
if charIndex <= 0 {
return true
}
let string = layoutManager.textStorage?.string as NSString?
return string?.character(at: charIndex - 1) == 32 ? true : false
}
}
var text = UITextView.init(frame: CGRect(x: 0, y: 0, width: 80, height: 100))
text.textContainer.layoutManager?.delegate = KRLayoutManagerDelegate()
text.text = "기사단장 길들이기"
text.text = "돈 공부는 처음이라"
text.text = "이야기 프랑스사"
@kiding
Copy link
Author

kiding commented Aug 19, 2020

macOS 11, iOS 14부터 hangulWordPriority를 사용할 수 있는 것으로 보입니다. 출처

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment