NSAttributedString

public extension NSAttributedString

AttributedString+Mutable provides the ability to modify an attributed string.

Author

Adamas

Version

1.9.0

Date

29/04/2022
  • Append a new attributed string to the end of the current one.

    Declaration

    Swift

    func appending(_ string: NSAttributedString) -> NSAttributedString

    Parameters

    string

    The new attributed string.

    Return Value

    The combined string

  • Add an underline to a substring.

    Declaration

    Swift

    func addingUnderline(toFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    substring

    The substring that should have an underline. Nil will apply the line to the whole string.

    Return Value

    A string with an underline.

  • Add linking function to a substring.

    Declaration

    Swift

    func addingLink(_ link: String,
                    toFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    link

    The url link to be applied.

    substring

    The clickable substring. Nil will apply the link to the whole string.

    Return Value

    A string with a link.

  • Change the font of a substring.

    Declaration

    Swift

    func changingFont(_ font: UIFont,
                      ofFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    font

    The new font to be applied.

    substring

    The substring that should be changed. Nil will apply the new font to the whole string.

    Return Value

    A string with part of the string applying the new font.

  • Strike cross part of the string.

    Declaration

    Swift

    func addingStrike(ofFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    substring

    The substring that should be crossed. Nil will apply the effect to the whole string.

    Return Value

    A string with part of it being crossed.

  • Change the color of a sub string.

    Declaration

    Swift

    func changingColor(_ color: UIColor,
                       ofFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    color

    The new color to apply.

    substring

    The substring that should apply the new color. Nil will apply the color to the whole string.

    Return Value

    A new string with part of it using the new color.

  • Change the letter spacing of a sub string.

    Declaration

    Swift

    func changingLetterSpacing(_ letterSpacing: CGFloat,
                               ofFirstSubstring substring: String? = nil) -> NSAttributedString

    Parameters

    letterSpacing

    The space between letters.

    substring

    The substring that should apply the new letter spacing. Nil will apply the letter spacing to the whole string.

    Return Value

    A new string with part of it using the new color.