ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - Nirma/Attributed: µframework for Attributed strings.
µframework for Attributed strings. Contribute to Nirma/Attributed development by creating an account on GitHub.
Visit Site

GitHub - Nirma/Attributed: µframework for Attributed strings.

GitHub - Nirma/Attributed: µframework for Attributed strings.

Attributed

Build Status CodeCov Swift 5.0 CocoaPods compatible Carthage compatible License

µframework for Attributed strings.

What is Attributed?

Attributed aims to be a drop in replacement to the current version of the NSAttributedString API.

The NSAttributedString interface has a few shortcomings. If you donʼt know the key and type of value needed to set a certain attribute, you have to spend time checking documentation. Another concern is safety: passing a dictionary of type [String: Any] to the constructor of NSAttributedString is a potential crash at runtime waiting to happen.

Attributed provides developers a nicer alternative by extending the current NSAttributedString interface with a fluent, strongly typed, and easy to use API.

Features

  • Create NSAttributedString instances with a strongly typed, simple, and fluid interface
  • Combine NSAttributedStrings with +
  • Partially apply Attributes to parts of an NSAttributedString by providing a Range

Donʼt see a feature you need?

Feel free to open an issue requesting the feature you want or send over a pull request!

Usage

Creating a new NSAttributedString by closure composition


"This is not a string".at.attributed {
  return $0.foreground(color: .red)
           .font(UIFont(name: "Chalkduster", size: 24.0)!)
           .underlineStyle(.styleSingle)
}

Creating a new NSAttributedString by passing an attributes object

First create an Attributes object:

let attributes = Attributes {
    return $0.foreground(color: .red)
             .font(UIFont(name: "Chalkduster", size: 24.0)!)
             .underlineStyle(.styleSingle)
}

then simply apply the Attributes to a String:

"Hello".at.attributed(with: attributes)

Combining NSAttributedString with +

This library defines an concatenation operator + for concatentating instances of NSAttributedString. + works with NSAttributedString no different than it does for String. This can be useful for combining NSAttributedStrings with different attributes to produce the desired effect without having to specify ranges to apply different attributes to.

let bodyAttributes = Attributes { 
    return $0.foreground(color: .purple)
             .font(UIFont(name: "Noteworthy-Light", size: 20.0)!)
}

let authorAttributes = bodyAttributes.foreground(color: .black)

"I think theres something strangely musical about noise.".at.attributed(with: bodyAttributes)
+ "\n  - Trent Reznor".at.attributed(with: authorAttributes)

Installation

Carthage

If you use Carthage to manage your dependencies, simply add Attributed to your Cartfile:

github "Nirma/Attributed"

If you use Carthage to build your dependencies, make sure you have added Attributed.framework to the "Linked Frameworks and Libraries" section of your target, and have included Attributed.framework in your Carthage framework copying build phase.

CocoaPods

If you use CocoaPods to manage your dependencies, simply add Attributed to your Podfile:

pod 'AttributedLib'

Requirements

  • Xcode 9.0
  • Swift 4.0+

Contribution

Contributions are more than welcome!

License

Attributed is free software, and may be redistributed under the terms specified in the LICENSE file.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory