Last active
April 21, 2021 06:07
-
-
Save kiding/8dccd25b536ebb510dcec5be57c48f6f to your computer and use it in GitHub Desktop.
word-break: keep-all; but in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "이야기 프랑스사" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
macOS 11, iOS 14부터
hangulWordPriority
를 사용할 수 있는 것으로 보입니다. 출처