A faster and more flexible label view for iOS
What is STULabel?
STULabel is an open source iOS framework for Swift and Objective-C that provides a label view (STULabel), a label layer (STULabelLayer) and a flexible API for thread-safe text layout and rendering (STUShapedString, STUTextFrame). The framework is implemented in Objective-C++ on top of the lower-level parts of the Core Text API. STULabel has a Swift overlay framework (STULabelSwift) that provides a convenient Swift API.
- Faster than UILabel and UITextView
- Optional asynchronous layout and rendering
- Support for prerendering (useful e.g. in a collection view prefetch handler)
- Automatic switching to efficient tiled rendering for very large labels
- Text highlighting with color or decorations that doesn’t require a text relayout
- Fast auto scaling of text (“shrink to fit size”)
- Interactive hyperlinks with full UIDragInteraction support
- Very flexible text truncation, including support for truncation tokens with embedded links and for multiple vertically stacked truncation scopes
- Auto Layout support
- Dynamic Type support
- UIAccessibility support
- Comprehensive support for right-to-left text
- Configurable vertical alignment and content insets
- Fine control over text layout, including support for fixed baseline distances and first baseline offsets
- Customizable automatic hyphenation
- Text attachments (inline images)
- Underlines with accurate descender gaps
- Flexible background decorations, e.g. with rounded corners
- Rich text layout information that is easy to query
The source code contains a demo app that you can build with the included Xcode project. The demo app contains:
- A viewer for the Universal Declaration of Human Rights that lets you view the document in languages with 39 different scripts (writing systems). You can experiment with fonts, spacings, text decorations, links, truncations, etc. and compare the text rendered by STULabel with the text rendered by UITextView.
- A UITableView scrolling stress test that lets you compare the performance of STULabel, UILabel and UITextView and observe the effect of enabling or disabling Auto Layout, async rendering or prefetch layout/rendering.
- A micro benchmark that lets you measure and compare the layout and render performance of STULabel, UILabel and UITextView for various test cases.
- A micro benchmark that lets you measure and compare the layout and render performance of STUTextFrame, NSStringDrawing and Text Kit for various test cases.
- A view that implements a “tap to read more” feature with STULabel.