Skip to content

Latest commit

 

History

History
105 lines (73 loc) · 3.32 KB

README.md

File metadata and controls

105 lines (73 loc) · 3.32 KB

Tribulus

Build Status Carthage Compatible Platform Swift 4.2 codecov License

Tribulus provides very convenient way to compose attributed strings. It is a framework based on applying custom Attributes class and nice chaining syntax.

Installation 🏁

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew with the following command:

$ brew update
$ brew install carthage

To integrate Tribulus into your Xcode project using Carthage, specify it in your Cartfile:

github "DmitryFrishbuter/Tribulus"

Run carthage update to build the framework and drag the built Tribulus.framework into your Xcode project.

Manually

Drag Sources folder from latest release into your project.

Usage 🏄‍

Initialization

To initialize attributed string with required attributes, you can use following code:

let attributedString = NSAttributedString(string: "Foo", style:
    TextStyle.font(.systemFont(ofSize: 14))
	     .color(.black)
	     .backgroundColor(.cyan)
	     .baselineOffset(14.0)
)

Appending

Tribulus also allows appending to existing mutable attributed string.

Here's a code for appending new attributed string:

let mAttributedString = NSAttributedString(string: "Foo")
	.asMutable()
	.append(" Bar", with: .color(.red))
	.append(" Baz", with: .direction(.horizontal))

And in the same simple way you can append any image:

let attributedString = NSMutableAttributedString(string: "Foo")
attributedString.append(UIImage(named: "Bar")!, bounds: CGRect(x: 0, y: 0, width: 40, height: 40))

Insertion

Moreover Tribulus allows you to insert newly configured attributed string at any location:

let attributedString = NSMutableAttributedString(string: "Foo  Baz")
attributedString.insert("Bar", with: .textEffect(.letterpressStyle), at: 4)

or to insert an image:

attributedString.insert(UIImage(named: "Bar")!, 
			bounds: CGRect(x: 0, y: 0, width: 40, height: 40), 
                        at: 0)

Additions

Instead on creating UIFontDescriptorSymbolicTraits you can just set bold and italic traits using Attributes object properties:

let attributedString = NSMutableAttributedString(string: testString)
attributedString.set(TextStyle.bold(true).italic(true))

Author 🖌

Dmitry Frishbuter, [email protected]

License 📃

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