Easy string decoration with styles

Overview

StyleDecorator

Language Version License Platform

Design string simply by linking attributes.

Example

Create Decorator with specific Style and link it at the end of needed string or wrap for styling:

"Style" + d1 + "Decorator" + d2 + "!"
// or
d1.wrap("Style") + d2.wrap("Decorator") + "!"

Example:

let a = Decorator(style: Style().foregroundColor(.black).kerning(-0.5).backgroundColor(.darkGray))
let b = Decorator(style: Style().foregroundColor(.white).backgroundColor(.black))
let c = Decorator(style: Style().foregroundColor(.gray).alignment(.right))

// You can write in syntax you prefer
let decoratedText = "Bold" + a + "Heavy" + b + "Black" + c
label.attributedText = NSAttributedString(decorator: decoratedText)

// or
let a1 = a.wrap, b1 = b.wrap, c1 = c.wrap
let decoratedText2 = a1("Bold") + b1("Heavy") + c1("Black")
label.attributedText = NSAttributedString(decorator: decoratedText2)

String can be designed dynamically:

// check Example for detailed code, where created 'd', 'e', 'f' etc

let titleText = "! " + ("Bold" + b + "Heavy" + c + "Black" + d)
let decoratedText = "Decorate attributed string simply" + a + "\n\n" + titleText + "\n\n" + "Right" + e + "\n" + "below black rect with red line" + f + "\n\n\nwith default attributes"

let defaultAttributes = Style()
    .font(UIFont.systemFont(ofSize: 15, weight: UIFontWeightBlack))
    .alignment(.center)
    .attributes

label.attributedText = NSAttributedString(decorator: decoratedText, attributes: defaultAttributes)

Requirements

Updated to Swift 5

Supports SPM

For Swift 4 version use v.0.4.2
For Swift 3.1 version use v.0.3.0

Installation

StyleDecorator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "StyleDecorator"

Author

Dmytro Pylypenko, [email protected]

License

StyleDecorator is available under the MIT license. See the LICENSE file for more info.

You might also like...
A Cross-Platform String and Regular Expression Library written in Swift.

Guitar 🎸 A Cross-Platform String and Regular Expression Library written in Swift. About This library seeks to add common string manipulation function

Swift emoji string parsing library
Swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji

An easy way to add mentions to uitextview like Facebook and Instagram
An easy way to add mentions to uitextview like Facebook and Instagram

OEMentions An easy way to add mentions to uitextview like Facebook and Instagram. It also include a tableview to show the users list to choose from. T

Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

A TextView that provides easy to use tagging feature for Mention or Hashtag
A TextView that provides easy to use tagging feature for Mention or Hashtag

Tagging A TextView that provides easy to use tagging feature for Mention or Hashtag. Introduction Tagging is a UIView that encloses a TextView that co

Acčento is an easy-to-use tool for adding Czech diacritics to copied text.
Acčento is an easy-to-use tool for adding Czech diacritics to copied text.

Acčento is an easy-to-use tool for adding Czech diacritics to copied text. The app lives in the menu bar and is activated using a global hot key.

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

StyledTextKit is a declarative attributed string library for fast rendering and easy string building.
StyledTextKit is a declarative attributed string library for fast rendering and easy string building.

StyledTextKit is a declarative attributed string library for fast rendering and easy string building. It serves as a simple replacement to NSAttribute

SmartString - A powerful and small library that will allow the creation of complex String Styles
SmartString - A powerful and small library that will allow the creation of complex String Styles

SmartString A powerful and small library that will allow the creation of complex

Swift String Validator. Simple lib for ios to validate string and UITextFields text for some criterias

Swift String validator About Library for easy and fastest string validation based on сciterias. Instalation KKStringValidator is available through Coc

KIEM - Open Source Library, converting mistyped Korean string into English string

KIEM Open Source Library, converting misspelled Korean string into English strin

It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.
It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

 CFAlertViewController CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and i

Easy Attributed String Creator
Easy Attributed String Creator

The main idea of this project is to have an online tool to be able to visually add formatting to a text and get back a swift and/or objective-c code t

Image slide-show viewer with multiple predefined transition styles, with ability to create new transitions with ease.
Image slide-show viewer with multiple predefined transition styles, with ability to create new transitions with ease.

ATGMediaBrowser ATGMediaBrowser is an image slide-show viewer that supports multiple predefined transition styles, and also allows the client to defin

Define UI styles in a hot-reloadable yaml or json file
Define UI styles in a hot-reloadable yaml or json file

Stylist 🎨 Stylist lets you define UI styles in a hot-reloadable external yaml or json theme file ✅ Define styles in external theme files ✅ Apply styl

Fashion is your helper to share and reuse UI styles in a Swifty way.
Fashion is your helper to share and reuse UI styles in a Swifty way.

Fashion is your helper to share and reuse UI styles in a Swifty way. The main goal is not to style your native apps in CSS, but use a set

Owner
Dmytro Pylypenko
Sociologist & Software Engineer. iOS Tech Lead at ZINIO.
Dmytro Pylypenko
Easy Attributed String Creator

The main idea of this project is to have an online tool to be able to visually add formatting to a text and get back a swift and/or objective-c code t

Andres Canal 283 Dec 27, 2022
BonMot is a Swift attributed string library

BonMot (pronounced Bon Mo, French for good word) is a Swift attributed string library. It abstracts away the complexities of the iOS, macOS, tvOS, and

Rightpoint 3.4k Dec 30, 2022
Croc is a swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji characters, making emoji-powered features an easy task for developers.

Joe Kalash 127 Nov 20, 2022
Great Swift String Pluralize Extension

Pluralize.swift Great Swift String Pluralize Extension case-insensitive tons of rules for irregular nouns (plural form) supports uncountable nouns all

Joshua Arvin Lat 193 Nov 8, 2022
👩‍🎨 Elegant Attributed String composition in Swift sauce

Elegant Attributed String composition in Swift sauce SwiftRichString is a lightweight library which allows to create and manipulate attributed strings

Daniele Margutti 2.9k Jan 5, 2023
A comprehensive, lightweight string extension for Swift

SwiftString SwiftString is a lightweight string extension for Swift. This library was motivated by having to search StackOverflow for common string op

Andrew Mayne 1.6k Dec 30, 2022
More powerful label, attributed string builder and text parser.

DDText More powerful label, attributed string builder and text parser. DDLabel More powerful label than UILabel, using TextKit. It supports features b

Daniel 16 Nov 8, 2022
String (and more) validation for iOS

Swift Validators ?? String validation for iOS. Contents Installation Walkthrough Usage Available validators License ReactiveSwift + SwiftValidators Wa

George Kaimakas 241 Nov 13, 2022
🌍⏩📄 Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.

ISO8859 Convert ISO8859 1-16 Encoded Text to String in Swift. Usage let encoding = ISO8859.part1 let string = String([...], iso8859Encoding: encoding)

Devran Cosmo Uenal 18 Jan 2, 2023