A Swifty API for attributed strings

Overview

SwiftyAttributes

A Swifty API for attributed strings.

Swift Version Swift Version Carthage compatible CocoaPods Compatible Platform Travis CI codecov.io


With SwiftyAttributes, you can create attributed strings like so:

let fancyString = "Hello World!".withTextColor(.blue).withUnderlineStyle(.styleSingle)

Alternatively, use the Attribute enum:

let fancyString = "Hello World!".withAttributes([
    .backgroundColor(.magenta),
    .strokeColor(.orange),
    .strokeWidth(1),
    .baselineOffset(5.2)
])

You can also easily combine attributed strings using a plus sign:

let fancyString = "Hello".withFont(.systemFont(ofSize: 12)) + " World!".withFont(.systemFont(ofSize: 18))

SwiftyAttributes has support for every attribute available in Cocoa and Cocoa Touch.

Requirements

  • iOS 8.0+, macOS 10.11+, watchOS 2.0+, tvOS 9.0+
  • Swift 4.2+
  • Xcode 10.0+

Installation

With CocoaPods

pod 'SwiftyAttributes'

With Carthage

github "eddiekaiger/SwiftyAttributes"

Usage

Initializing attributed strings in SwiftyAttributes can be done several ways:

  • Using the with[Attribute] extensions:

    "Hello World".withUnderlineColor(.red).withUnderlineStyle(.styleDouble)
  • Using the Attribute enum extensions:

    "Hello World".withAttributes([.underlineColor(.red), .underlineStyle(.styleDouble)])
  • Using the Attribute enum in an initializer:

    NSAttributedString(string: "Hello World", swiftyAttributes: [.kern(5), .backgroundColor(.gray)])

You can retrieve the attribute at a specific location using the built-in NSAttributedString.Key enum:

let attr: Attribute? = myAttributedString.swiftyAttribute(.shadow, at: 5)

Several API methods are provided to use these new enums as well as Swift's Range type instead of NSRange. Some of the method signatures include:

extension NSMutableAttributedString {
    func addAttributes(_ attributes: [Attribute], range: Range<Int>)
    func addAttributes(_ attributes: [Attribute], range: NSRange)
    func setAttributes(_ attributes: [Attribute], range: Range<Int>)
    func setAttributes(_ attributes: [Attribute], range: NSRange)
    func replaceCharacters(in range: Range<Int>, with str: String)
    func replaceCharacters(in range: Range<Int>, with attrString: NSAttributedString)
    func deleteCharacters(in range: Range<Int>)
    func removeAttribute(_ name: NSAttributedStringKey, range: Range<Int>)
}

extension NSAttributedString {
    convenience init(string str: String, swiftyAttributes: [Attribute])
    func withAttributes(_ attributes: [Attribute]) -> NSMutableAttributedString
    func withAttribute(_ attribute: Attribute) -> NSMutableAttributedString
    func attributedSubstring(from range: Range<Int>) -> NSAttributedString
    func swiftyAttribute(_ attrName: NSAttributedStringKey, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute?
    func swiftyAttributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)]
    func enumerateSwiftyAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
    func enumerateSwiftyAttribute(_ attrName: NSAttributedStringKey, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
}

extension String {
    var attributedString: NSMutableAttributedString
    func withAttributes(_ attributes: [Attribute]) -> NSMutableAttributedString
    func withAttribute(_ attribute: Attribute) -> NSMutableAttributedString
}

// ... and more!

Support

For questions, support, and suggestions, please open up an issue.

License

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

Comments
  • AttributedString+SwiftyAttributes.swift:95:29: Generic parameter 'Element' could not be inferred

    AttributedString+SwiftyAttributes.swift:95:29: Generic parameter 'Element' could not be inferred

    Hi Eddie,

    I got this error when i wanna compile the app.

    Pods/SwiftyAttributes/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift:95:29: Generic parameter 'Element' could not be inferred

    opened by kohdesmond 12
  • Instantiating an NSMutableAttributedString while importing SwiftyAttributes causes build error on Xcode 10

    Instantiating an NSMutableAttributedString while importing SwiftyAttributes causes build error on Xcode 10

    We've had this issue in our project preventing Xcode 10 compilation since the release. The error is:

    Foundation.NSMutableAttributedString:11:12: note: found this candidate
        public init(string str: String, attributes attrs: [NSAttributedStringKey : Any]? = nil)
               ^
    Foundation.NSAttributedString:19:12: note: found this candidate
        public init(string str: String, attributes attrs: [NSAttributedStringKey : Any]? = nil)
    

    The usage was pretty basic, something like so:

    let string = NSMutableAttributedString(string: "Hello World", attributes: [.strokeColor: UIColor.green])
    

    After digging into it I discovered this doesn't happen unless we're importing SwiftyAttributes. If you duplicate the testInit_withStringAndAttributes test method, but replace the NSAttributedStrings with NSMutableAttributedStrings you'll get the same error when running the tests.

    Attempting to use the convenience initializer on a NSMutableAttributedString results in the following error:

    Cannot convert value of type '[Attribute]' to expected argument type '[NSAttributedStringKey : Any]?'
    

    Taking out the convenience initializer on NSAttributedString, or giving the attributes parameter a different name resolves the issue.

    It's likely that this is a bug with Swift. I'm not sure if you'd rather file a bug with them and see what happens, or resolve the issue within the library now. Changing the attributes parameter would be a breaking change and be cause for a major bump.

    Let me know if you're going to take action on this at the library level if ya can, as it is preventing us from building on XC10 :)

    Here's the diff w/ the fix and test that I experimented with:

    diff --git a/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift
    index 76a0b01..6c3a934 100644
    --- a/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift
    +++ b/SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift
    @@ -30,8 +30,8 @@ extension NSAttributedString {
          - parameter    str:            The string for the new attributed string.
          - parameter    attributes:     The attributes for the new attributed string.
          */
    -    public convenience init(string str: String, attributes: [Attribute]) {
    -        self.init(string: str, attributes: dictionary(from: attributes))
    +    public convenience init(string str: String, swiftyAttributes attrs: [Attribute]) {
    +        self.init(string: str, attributes: dictionary(from: attrs))
         }
     
         /**
    diff --git a/SwiftyAttributesTests/NSAttributedString_Tests.swift b/SwiftyAttributesTests/NSAttributedString_Tests.swift
    index 60947b3..79845e4 100644
    --- a/SwiftyAttributesTests/NSAttributedString_Tests.swift
    +++ b/SwiftyAttributesTests/NSAttributedString_Tests.swift
    @@ -12,7 +12,7 @@ import SwiftyAttributes
     class NSAttributedString_Tests: XCTestCase {
         
         func testInit_withStringAndAttributes() {
    -        let subject = NSAttributedString(string: "Hello World", attributes: [.strokeColor(.green), .strokeWidth(3)])
    +        let subject = NSAttributedString(string: "Hello World", swiftyAttributes: [.strokeColor(.green), .strokeWidth(3)])
             #if swift(>=4.0)
                 let expected = NSAttributedString(string: "Hello World", attributes: [.strokeColor: Color.green, .strokeWidth: 3])
             #else
    diff --git a/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift b/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift
    index 5577b2e..f95aba3 100644
    --- a/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift
    +++ b/SwiftyAttributesTests/NSMutableAttributedString_Tests.swift
    @@ -10,6 +10,16 @@ import XCTest
     import SwiftyAttributes
     
     class NSMutableAttributedString_Tests: XCTestCase {
    +
    +    func testInitMutable_withStringAndAttributes() {
    +        let subject = NSMutableAttributedString(string: "Hello World", swiftyAttributes: [.strokeColor(.green), .strokeWidth(3)])
    +        #if swift(>=4.0)
    +        let expected = NSMutableAttributedString(string: "Hello World", attributes: [.strokeColor: Color.green, .strokeWidth: 3])
    +        #else
    +        let expected = NSMutableAttributedString(string: "Hello World", attributes: [NSStrokeColorAttributeName: Color.green, NSStrokeWidthAttributeName: 3])
    +        #endif
    +        XCTAssertEqual(subject, expected)
    +    }
         
         func testAddAttributes_usingSwiftRange() {
             let subject = "Hello".withTextColor(.orange)
    
    opened by ketzusaka 7
  • withLink Fails

    withLink Fails

    See this test

            let r1 = "Hi ".withTextColor(.black).withFont(UIFont(name: "Futura-Medium", size: 10.0)!)
            let r2 = "Google".withTextColor(.black).withUnderlineStyle(.styleSingle).withFont(UIFont(name: "Futura-Medium", size: 10.0)!).withLink(URL(string: "https://www.google.com")!)
            let r3 = " and ".withTextColor(.black).withFont(UIFont(name: "Futura-Medium", size: 10.0)!)
            let r4 = "Yahoo".withTextColor(.black).withUnderlineStyle(.styleSingle).withFont(UIFont(name: "Futura-Medium", size: 10.0)!).withLink(URL(string: "https://www.yahoo.com")!)
            
            blaBlaBla.attributedText = r1 + r2 + r3 + r4
            blaBlaBla.isUserInteractionEnabled = true
    

    Links are not clickable.

    opened by drieran 4
  • UINavigationBar wrappers

    UINavigationBar wrappers

    Hello. In this pull request I added wrappers for UINavigationBar.titleTextAttributes and UINavigationBar.largeTitleTextAttributes. Use cocoapods 1.7.0.

    opened by RomanPodymov 3
  • Crashes with custom NSAttributedStringKey

    Crashes with custom NSAttributedStringKey

    When working with NSAttributedStrings that use custom NSAttributedStringKey values, SwiftyAttributes crashes whenever attributes are accessed.

    Here's one way to reproduce:

    let attributedString = NSMutableAttributedString(string: "hello world")
    attributedString.setAttributes([NSAttributedStringKey("crash"): "bang"], range: NSRange(..<attributedString.length))
    attributedString.enumerateSwiftyAttributes(in: 0..<attributedString.length) { attributes, _, _ in
        debugPrint(attributes)
    }
    

    I realize that type-safety for a finite number of Foundation values is part of SwiftyAttributes's appeal, but I also think this crash should be handled by the library due to the existence of NSAttributedStringKey(string:).

    I haven't given too much thought into how I think this could be handled, but perhaps something like: .custom([String: Any]) is an appropriate solution for any NSAttributedStringKey values that can't be constructed via NSAttributedStringKey(rawValue:).

    FWIW, this came up due to some work I'm doing with markdown rendering, where we're storing the URL for links in a custom attribute as part of the attributed string.

    opened by scalessec 3
  • Use of unresolved identifier 'SpellingState' on macOS

    Use of unresolved identifier 'SpellingState' on macOS

    Installed via cocoa pods, got the error above.

    Disappeared after adding public typealias SpellingState = NSAttributedString.SpellingState in Attribute.swift:L15.

    opened by Schaefers 3
  • Collision with Foundation:  `NSAttributedString`'s `enumerateAttributes` method

    Collision with Foundation: `NSAttributedString`'s `enumerateAttributes` method

    I'm getting a collision with Foundation with the NSAttributedString method enumerateAttributes:

    Ambiguous reference to member 'enumerateAttribute(_:in:options:using:)'
    
    opened by zachlucas 3
  • Convert an array of attributes to a dictionary

    Convert an array of attributes to a dictionary

    Hey @eddiekaiger, first off thanks for the really useful library -- It's already been a huge timesaver for me.

    Maybe I'm overlooking it, but is there a convenient way to go from [Attribute] to [String: Any]?

    I keep running into situations like this:

    let attributes: [Attribute] = [.font(UIFont.systemFont(ofSize: 15.0)), .textColor(.red)]
    UINavigationBar.appearance().titleTextAttributes = ??
    

    An extension of [Attribute] would be a pretty awesome way to handle this (if it's even possible). Thoughts?

    opened by scalessec 3
  • iOS 13设备出现的问题

    iOS 13设备出现的问题

    CoreText note: Client requested name ".SFUI-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].

    opened by FunnyerFeng 2
  • More wrappers

    More wrappers

    Hello. As I wrote before here is a pull request with more wrappers. However I don't know how can I write tests for these functions to pass the Codecov check.

    opened by RomanPodymov 2
  • Get color of underlined text

    Get color of underlined text

    Hello

    I'm using this library on macOS with Swift for a project. So, basically, I want to get the color of the underlined text in my NSTextStorage of my NSTextView. This library is very good to create attributes, modify and even delete, but I wonder how to access the color.

    Thanks any advance for your ideas. 😄

    opened by popo63301 2
  • Bump tzinfo from 1.2.5 to 1.2.10

    Bump tzinfo from 1.2.5 to 1.2.10

    Bumps tzinfo from 1.2.5 to 1.2.10.

    Release notes

    Sourced from tzinfo's releases.

    v1.2.10

    TZInfo v1.2.10 on RubyGems.org

    v1.2.9

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    TZInfo v1.2.9 on RubyGems.org

    v1.2.8

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    TZInfo v1.2.8 on RubyGems.org

    v1.2.7

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    TZInfo v1.2.7 on RubyGems.org

    v1.2.6

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.

    TZInfo v1.2.6 on RubyGems.org

    Changelog

    Sourced from tzinfo's changelog.

    Version 1.2.10 - 19-Jul-2022

    Version 1.2.9 - 16-Dec-2020

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    Version 1.2.8 - 8-Nov-2020

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    Version 1.2.7 - 2-Apr-2020

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    Version 1.2.6 - 24-Dec-2019

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.
    Commits
    • 0814dcd Fix the release date.
    • fd05e2a Preparing v1.2.10.
    • b98c32e Merge branch 'fix-directory-traversal-1.2' into 1.2
    • ac3ee68 Remove unnecessary escaping of + within regex character classes.
    • 9d49bf9 Fix relative path loading tests.
    • 394c381 Remove private_constant for consistency and compatibility.
    • 5e9f990 Exclude Arch Linux's SECURITY file from the time zone index.
    • 17fc9e1 Workaround for 'Permission denied - NUL' errors with JRuby on Windows.
    • 6bd7a51 Update copyright years.
    • 9905ca9 Fix directory traversal in Timezone.get when using Ruby data source
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump cocoapods-downloader from 1.2.2 to 1.6.3

    Bump cocoapods-downloader from 1.2.2 to 1.6.3

    Bumps cocoapods-downloader from 1.2.2 to 1.6.3.

    Release notes

    Sourced from cocoapods-downloader's releases.

    1.6.3

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.2

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.1

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.0

    Enhancements
    • None.
    Bug Fixes
    • Adds a check for command injections in the input for hg and git.
      orta #124

    1.5.1

    Enhancements
    • None.
    Bug Fixes
    • Fix "can't modify frozen string" errors when pods are integrated using the branch option
      buju77 #10920

    1.5.0

    ... (truncated)

    Changelog

    Sourced from cocoapods-downloader's changelog.

    1.6.3 (2022-04-01)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.2 (2022-03-28)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.1 (2022-03-23)

    Enhancements
    • None.
    Bug Fixes
    • None.

    1.6.0 (2022-03-22)

    Enhancements
    • None.
    Bug Fixes
    • Adds a check for command injections in the input for hg and git.
      orta #124

    1.5.1 (2021-09-07)

    Enhancements
    • None.

    ... (truncated)

    Commits
    • c03e2ed Release 1.6.3
    • f75bccc Disable Bazaar tests due to macOS 12.3 not including python2
    • 52a0d54 Merge pull request #128 from CocoaPods/validate_before_dl
    • d27c983 Ensure that the git pre-processor doesn't accidentally bail also
    • 3adfe1f [CHANGELOG] Add empty Master section
    • 591167a Release 1.6.2
    • d2564c3 Merge pull request #127 from CocoaPods/validate_before_dl
    • 99fec61 Switches where we check for invalid input, to move it inside the download fun...
    • 96679f2 [CHANGELOG] Add empty Master section
    • 3a7c54b Release 1.6.1
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • In iOS12, 13, the withTextColor does not display text immediately

    In iOS12, 13, the withTextColor does not display text immediately

    Hello. 😄 I have a problem in iOS 12, 13. It is normal for versions iOS 14 and above. The first time I open the screen with the NSMutableAttributedString, the withTextColor() does not apply. And i also have a problem in withAttributes([.textColor()]. When I scroll through the screen with the NSMutableAttributedString and come back, the text color will appear as I wish. I'd like to know a solution.

    opened by jaeeunlee322 2
  • Assigning a TextAttachment does not apply the image I assigned in the attachment

    Assigning a TextAttachment does not apply the image I assigned in the attachment

    Here is a real example of the issue I'm facing:

    An attributed text with an icon set in a UIButton.

    let button = UIButton(type: .system)
    let attachment = TextAttachment()
    attachment.image = MediaActionType.connect.iconImage
    let attributedString = "".withAttachment(attachment) + " Connect With \(name)".withTextColor(.brand).withFont(.brandon(style: .medium, size: 16.0))
    button.setAttributedTitle(attributedString, for: .normal)
    

    This doesn't show the icon but if works if I use NSMutableAttributedString directly:

    let button = UIButton(type: .system)
    let attachment = TextAttachment()
    attachment.image = MediaActionType.connect.iconImage
    let mutableAttributedString = NSMutableAttributedString()
    mutableAttributedString.append(NSAttributedString(attachment: attachment))
    mutableAttributedString.append(" Connect With \(name)".withTextColor(.brand).withFont(.brandon(style: .medium, size: 16.0)))
    button.setAttributedTitle(mutableAttributedString, for: .normal)
    

    I'm using Xcode 13.1, CocoaPods and SwiftyAttributes version is 5.1.1. Any thoughts? Thank you.

    opened by ricardopereira 0
  • Feature Request: setAttribute and addAttribute overrides w/o range

    Feature Request: setAttribute and addAttribute overrides w/o range

    Would be pretty sweet to have methods that set attributes on the whole range. Override existing methods without a range param will set attributes for the whole range.

        func addAttributes(_ attributes: [Attribute])
        func addAttributes(_ attributes: [Attribute])
        func setAttributes(_ attributes: [Attribute])
        func setAttributes(_ attributes: [Attribute])
    
    opened by thejeff77 1
Releases(v5.2.0)
  • v5.2.0(May 15, 2020)

  • v5.1.1(Apr 24, 2019)

  • v5.1.0(Apr 4, 2019)

  • v5.0.0(Jun 25, 2018)

    This release updates the labels in the convenience initializer because it seems that the Swift compiler finds it conflicting with the initializer for NSAttributedString (see #29 and #30). This is a breaking change that will only affect people who use the convenience initializer.

    Source code(tar.gz)
    Source code(zip)
  • v4.3.0(Jun 5, 2018)

    You can now use SwiftyAttributes with Swift 4.2 and Xcode 10! The library still works with Swift 3, lower versions of Swift 4, and Xcode 9. 🙌

    Source code(tar.gz)
    Source code(zip)
  • v4.2.0(Apr 27, 2018)

  • v4.1.1(Apr 10, 2018)

  • v4.1.0(Sep 18, 2017)

  • v4.0.0(Sep 16, 2017)

  • v3.2.0(Sep 7, 2017)

  • v3.1.0(Dec 13, 2016)

    • Multiplatform support (iOS, macOS, watchOS, tvOS)
    • Additional macOS-specific attributes
    • Added VerticalGlyphForm enum and attribute
    • Methods to convert between attribute dictionaries and Attribute arrays (#6)
    • Methods to enumerate attributes
    • Example app for macOS
    • Lots of tests
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Nov 7, 2016)

    This release provides a more fully-featured, Swifty API for most uses cases of attributed strings on iOS. Updates include:

    • A new Attribute enum that serves as a replacement for the key-value pairs of Foundation's API for attributed strings
    • New extensions for adding, modifying, and reading attributes using the new Attribute enum
    • More "Swifty" alternative methods for NSAttributedString and NSMutableAttributedString
    • Support for iOS 8
    • And more... !
    Source code(tar.gz)
    Source code(zip)
  • v2.0(Oct 6, 2016)

  • v1.0(Nov 25, 2015)

Owner
Eddie Kaiger
Senior Mobile Engineer @instacart
Eddie Kaiger
Texstyle allows you to format iOS attributed strings easily.

Texstyle allows you to format attributed strings easily. Features Applying attributes with strong typing and autocompletion Cache for attributes Subst

Rosberry 79 Sep 9, 2022
An easier way to compose attributed strings

TextAttributes makes it easy to compose attributed strings. let attrs = TextAttributes() .font(name: "HelveticaNeue", size: 16) .foregroundCol

Damien 2.2k Dec 31, 2022
A simple library for building attributed strings, for a more civilized age.

Veneer A simple library for building attributed strings, for a more civilized age. Veneer was created to make creating attributed strings easier to re

Wess Cope 26 Dec 27, 2022
Easiest way to create an attributed UITextView (with support for multiple links and from html)

AttributedTextView Easiest way to create an attributed UITextView (with support for multiple links and html). See the demo app and the playground for

Edwin Vermeer 430 Nov 24, 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
👩‍🎨 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
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
A quick helper for setting attributed texts to UILabel.

UILabelAttributedTextHelper A quick helper for setting attributed texts to UILabel. Sample usage: label.setAttributedText( leadingText: "H

Glenn Posadas 5 Aug 24, 2022
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
A library for formatting strings on iOS and macOS

Sprinter Introduction What? Why? How? Usage Installation Integration Localization Thread Safety Advanced Usage Introduction What? Sprinter is a librar

Nick Lockwood 168 Feb 6, 2022
🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it.

Mustard ?? Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. Quick start using character sets Foundation

Mathew Sanders 695 Nov 11, 2022
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.

SwiftyMarkdown 1.0 SwiftyMarkdown converts Markdown files and strings into NSAttributedStrings using sensible defaults and a Swift-style syntax. It us

Simon Fairbairn 1.5k Dec 22, 2022
A Swift framework for using custom emoji in strings.

Emojica – a Swift framework for using custom emoji in strings. What does it do? Emojica allows you to replace the standard emoji in your iOS apps with

Dan 101 Nov 7, 2022
Generate SwiftUI Text or AttributedString from markdown strings with custom style names.

iOS 15.0 / macOS 12.0 / tvOS 15.0 / watchOS 8.0 StyledMarkdown is a mini library that lets you define custom styles in code and use them in your local

null 19 Dec 7, 2022
A standalone, flexible API that provides a full-featured rich text editor for iOS applications.

Twitter Text Editor A standalone, flexible API that provides a full featured rich text editor for iOS applications. This provides a robust text attrib

Twitter 2.8k Dec 29, 2022
µframework for Attributed strings.

Attributed µframework for Attributed strings. What is Attributed? Attributed aims to be a drop in replacement to the current version of the NSAttribut

Nicholas Maccharoli 754 Jan 9, 2023
Texstyle allows you to format iOS attributed strings easily.

Texstyle allows you to format attributed strings easily. Features Applying attributes with strong typing and autocompletion Cache for attributes Subst

Rosberry 79 Sep 9, 2022
An easier way to compose attributed strings

TextAttributes makes it easy to compose attributed strings. let attrs = TextAttributes() .font(name: "HelveticaNeue", size: 16) .foregroundCol

Damien 2.2k Dec 31, 2022
A simple library for building attributed strings, for a more civilized age.

Veneer A simple library for building attributed strings, for a more civilized age. Veneer was created to make creating attributed strings easier to re

Wess Cope 26 Dec 27, 2022
JSONHelper - ✌ Convert anything into anything in one operation; JSON data into class instances, hex strings into UIColor/NSColor, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of!

JSONHelper Convert anything into anything in one operation; hex strings into UIColor/NSColor, JSON strings into class instances, y/n strings to boolea

Baris Sencan 788 Jul 19, 2022