Texstyle allows you to format attributed strings easily.
Features
- Applying attributes with strong typing and autocompletion
- Cache for attributes
- Substyles
- Convenient extensions for
String
andUIButton
Requirements
- iOS 9.0+ / tvOS 9.0+
- Xcode 10.0+
Usage
Here is a basic example of Texstyle using:
The result:
Let's start with text styles. There is a TextStyle
class for configuring different style parameters like font, color, kerning etc. We prefer to use TextStyle
extension for app specific styles:
It allows you to reuse the styles across the app.
Next, create a Text
instance. It contains string value and style:
Text also supports independent styles for each UIControl.State
. For example, if you want to use a different style for button highlight state, you should initialize text like:
To create an attributed string, just use:
All attributed strings are cached by default. It's useful in reusable elements like UICollectionViewCell
or UITableViewCell
.
There are custom operators for texts and strings:
There are convenience APIs for text creation and applying:
Check TexstyleExample project for more examples.
Cache
TextStyle and Text classes have internal cache to prevent extra calculation. TextStyle caches attributes and invalidates it on any attribute change. Text has cached attributed strings for states. For example, if you use texts in collection view cells and want to update some labels in it after reuse, texts return cached strings. Please note that texts won't invalidate cached strings if you update textstyle attributes.
Installation
Depo
Depo is a universal dependency manager that combines Carthage, SPM and CocoaPods and provides common user interface to all of them.
To install Texstyle
via Carthage using Depo you need to add this to your Depofile
:
To install Texstyle via CocoaPods
Add this to your Depofile:CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Alamofire into your Xcode project using CocoaPods, specify it in your Podfile
:
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile
:
Documentation
Read the docs. Generated with jazzy. Hosted by GitHub Pages.
About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide ?.
Check out our open source projects, read our blog or give us a high-five on ? @rosberryapps.
License
Texstyle is available under the MIT license. See the LICENSE file for more info.