-
-
Save laevandus/3fbd593dac57424d929c755e7595decf to your computer and use it in GitHub Desktop.
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
private func preparedTextStorage() -> NSTextStorage? { | |
guard let attributedText = attributedText, attributedText.length > 0 else { return nil } | |
// Creates and configures a text storage which matches with the UILabel's configuration. | |
let layoutManager = NSLayoutManager() | |
let textContainer = NSTextContainer(size: bounds.size) | |
textContainer.lineFragmentPadding = 0 | |
let textStorage = NSTextStorage(string: "") | |
layoutManager.addTextContainer(textContainer) | |
textStorage.addLayoutManager(layoutManager) | |
textContainer.lineBreakMode = lineBreakMode | |
textContainer.size = textRect(forBounds: bounds, limitedToNumberOfLines: numberOfLines).size | |
textStorage.setAttributedString(attributedText) | |
return textStorage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment