styled-text alternatives and similar libraries
Based on the "TextField & TextView" category.
Alternatively, view styled-text alternatives based on common mentions on social networks and blogs.
-
JVFloatLabeledTextField
UITextField subclass with floating labels - inspired by Matt D. Smith's design: http://dribbble.com/shots/1254439--GIF-Mobile-Form-Interaction?list=users -
SkyFloatingLabelTextField
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift. -
PYSearch
π An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) . -
Reel Search
:octocat: π RAMReel is a UI controller that allows you to choose options from a list. Swift UI library made by @Ramotion -
NextGrowingTextView
π The next in the generations of 'growing textviews' optimized for iOS 8 and above. -
InputBarAccessoryView
A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments -
RPFloatingPlaceholders
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text. -
KMPlaceholderTextView
A UITextView subclass that adds support for multiline placeholder written in Swift. -
InstantSearch iOS
β‘οΈ A library of widgets and helpers to build instant-search applications on iOS. -
UITextField-Navigation
πββοΈ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews -
PasswordTextField
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies -
CocoaTextField
Apple TextField created according to the Material.IO guidelines of 2019. Featured at Medium. -
ARAutocompleteTextView
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or @alexruperez. -
CHIOTPField
CHIOTPField is a set of textfields that can be used for One-time passwords, SMS codes, PIN codes, etc. Mady by @ChiliLabs - https://chililabs.io -
AwesomeTextField
Awesome TextField is a nice and simple libriary for iOS and Mac OSX. It's highly customisable and easy-to-use tool. Works perfectly for any registration or login forms in your app. -
CBPinEntryView
A customisable view for entering arbitrary length pins, codes or passwords in iOS. Supports iOS 12 one time codes. -
Streamoji
DISCONTINUED. :godmode: Custom emoji rendering library for iOS apps with support for GIF & still images - plug-in extension for UITextView - performance, cache β - Made with π by @GetStream -
MBAutoGrowingTextView
DISCONTINUED. An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height -
MVAutocompletePlaceSearchTextField
iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more apps having maps. -
RSFloatInputView
A Float Input View with smooth animation and supporting icon and seperator written with Swift -
NxEnabled
DISCONTINUED. Library that allows you binding `enabled` property of button with textable elements (TextView, TextField)
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of styled-text or a related project?
README
Β Β Β StyledTextΒ Β
StyledText is a library that simplifies styling dynamic text in iOS applications. Instead of having to use attributed strings every time you need to update text, you can declaratively set a text style on your labels. When the text of the label is updated, the label uses the preset style.
Before
let label = UILabel()
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4.0
let attributes: [String: Any] = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14),
NSForegroundColorAttributeName: UIColor.blue,
NSKernAttributeName: 1.5,
NSParagraphStyleAttributeName: paragraphStyle]
let string = NSAttributedString(string: "This is a string",
attributes: attributes)
label.attributedText = string
let newString = NSAttributedString(string: "This is a new string",
attributes: attributes)
label.attributedText = newString
After
let styledLabel = StyledLabel()
styledLabel.textStyle = TextStyle(font: .boldSystemFont(ofSize: 14), color: .blue, lineSpacing: 4.0, kern: 1.5)
styledLabel.text = "This is a string"
styledLabel.text = "This is a new string"
Installation
- Add this line to your Podfile:
pod "StyledText"
- Run a
pod install
- You're all set!
How to Use
Getting started with StyledText is easy, just add a StyledLabel
to your view and provide it with a TextStyle
. After that, it behaves like any other UILabel
. Changes to the label's text
property will always use the set textStyle
.
class ViewController: UIViewController {
private let styledLabel: StyledLabel = {
let label = StyledLabel(frame: .zero)
label.textStyle = TextStyle(font: .boldSystemFont(ofSize: 24.0),
color: .orange)
return label
}()
}
TextStyle
A TextStyle
represents the attributes a styled view should use to draw its text. Many different text formatting options are supported, including those that previously required interaction with attributed strings or paragraph styles, such as kerning and line spacing. Creating a TextStyle
is easy, just specify a font along with any other attributes you want to define. Any unspecified attributes simply remain as system defaults.
let style = TextStyle(font: .italicSystemFont(ofSize: 72),
color: .magenta,
lineSpacing: 10,
lineHeightMultiple: 2.0,
kern: -0.5,
alignment: .left,
lineBreakMode: .byTruncatingMiddle)
let blueStyle = style.with(color: .blue)
let redStyle = style.with(color: .red)
Providing Defaults
You probably have a sensible default value for kerning that works well for your font. Instead of needing to specify this kern value in each individual TextStyle
you create, you can use a TextStyleDefaultsGenerator
to add it automatically. The simplest way to get started with this is to extend TextStyle
to conform to the TextStyleDefaultsGenerator
protocol, the library will detect if you've added this conformance and behave appropriately.
extension TextStyle: TextStyleDefaultsGenerator {
private static let defaultCeraKern: CGFloat = -0.2
private static let defaultChronicleKern: CGFloat = -0.2
static public func defaultKern(for font: UIFont) -> CGFloat? {
if font.fontName.contains("Cera") {
return defaultCeraKern
} else if font.fontName.contains("Chronicle") {
return defaultChronicleKern
}
return nil
}
}
Dynamic Type Support
StyledText supports scaling text content to the system font size, a feature Apple calls Dynamic Type. To use this feature, set the dynamicTypeBehavior
property of a TextStyle
to one of these values:
noScaling
: [default] keep the font size constant, even when the system font size changesscaleToStandardSizes
: scale the font to all standard system font sizes, larger accessibility sizes are capped at the maximum standard sizescaleToAllSizes
: scale the font to all standard and accessiblity font sizes
It's possible for the font size to change while your application is running. When this occurs, you'll need to call refreshStyle()
on any styled components that are visible for the size to update. A good way to listen for this event is by adding a delegate to the shared DynamicTypeController
:
class MyViewController: UIViewController, DynamicTypeControllerDelegate {
let label: StyledLabel = {
let label = StyledLabel()
label.textStyle = TextStyle(font: .boldSystemFont(ofSize: 14), color: .black, dynamicTypeBehavior: .scaleToStandardSizes)
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
DynamicTypeController.shared.addDelegate(self)
}
func preferredContentSizeCategoryDidUpdate(controller: DynamicTypeController, newCategory: UIContentSizeCategory){
label.refreshStyle()
}
}
Styled Components
To enable automatic styling, StyledText uses a number of view subclasses that are simple swap-in replacements for conventional UIKit components.
StyledText View | Replaces UIKit View |
---|---|
StyledLabel | UILabel |
StyledTextView | UITextView |
StyledButton* | UIButton |
[*] Using StyledButton
StyledButton
provides text style properties for each UIControlState
button state.
Control State | Text Style Property |
---|---|
.normal | normalTextStyle |
.highlighted | highlightedTextStyle |
.disabled | disabledTextStyle |
.selected | selectedTextStyle |
License
StyledText is available under the MIT license. See the LICENSE file for more info.
*Note that all licence references and agreements mentioned in the styled-text README section above
are relevant to that project's source code only.