MAGNSAttributedStringFormat 0.3.2

MAGNSAttributedStringFormat 0.3.2

TestsTested
LangLanguage SwiftSwift
License Apache 2
ReleasedLast Release Feb 2018
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Nikita Kazakov.



  • By
  • Nikita Kazakov

MAGNSAttributedStringFormat

Version
License
Platform

An extension to NSAttributedString for creating attributed strings by using a
given format string.

Use with attributes to set attributes for the entire string

NSAttributedString.attributedStringWith(attributes: [NSAttributedStringKey : Any], format: NSString, arguments: NSAttributedString...)

Use without attributes to set attributes only for arguments

NSAttributedString.attributedStringWith(format: NSString, arguments: NSAttributedString...)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

one = NSAttributedString(string: "one", attributes: [
NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 23),
NSAttributedStringKey.foregroundColor: UIColor.blue
])

two = NSAttributedString(string: "two", attributes: [
NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 23),
NSAttributedStringKey.foregroundColor: UIColor.green
])

three = NSAttributedString(string: "three", attributes: [
NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 23),
NSAttributedStringKey.foregroundColor: UIColor.red
])

etc = NSAttributedString(string: "etc", attributes: [
NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 23),
NSAttributedStringKey.foregroundColor: UIColor.gray
])

result = NSAttributedString.attributedStringWith(format: "You can multiple (%@, %@, %@, %@) arguments with their attributes each of them", arguments: one, two, three, etc)

Installation

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

Podfile

pod 'MAGNSAttributedStringFormat'

Author

Nikita Kazakov, [email protected]

License

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