When you want to compose a string of text that is attributed to a single person, you have to use the “&” character. The problem is that it is hard to type it, and it is even harder to remember. Wouldn’t it be nice if you could simply insert the “&” character and the “&” character would combine? You could simply type “&and” and the “&” character would be replaced by the “and” character.

If you write a lot of code and go back to read your past code, you may have noticed that the code you wrote a few days ago looks really different to the code you wrote a week ago. This is because the syntax you use to write the code has changed, often due to new features or changes in the style guide.

In my previous post, I showed how to write a string based on the attribute of another string in the same way as how we write a regular string. The problem is that we have to pre-compute all the integers and apply the ReplacingCharacter to each to make the attribute string. However, we could use a different approach to make the attribute string more efficiently.

Text feature

With TextAttributes, you can easily compile assigned character strings.

let attrs = TextAttributes()
.font(name : HelveticaNeue, size : 16)
.foregroundColor(white : 0.2, alpha : 1)

NSAttributedString(string : The brown and quick fox jumps over the lazy dog, attributes : attrs)


  • x] Strongly typed features
  • x] Chain adjustment methods
  • x] Direct access to NSParagraphStyle properties
  • x] Improved auto-fill function


  • Obtain or set TextAttributes properties:

attrs.font = UIFont(name : HelveticaNew, size : 16)
attrs.backgroundColor = .white

View all articles

The TextAttributes methods return Self to enable method chaining:


Show all methods

  • Methods are also constructors:

The following are equivalent:

.font(name: HelveticaNew, size: 16)
.foregroundColor(white: 0.2, alpha: 1)

font = UIFont(name : HelveticaNeue, size : 16)
lets color = UIColor(white : 0.2, alpha : 1)


  • Access to basic vocabulary :

attrs.dictionary // Returns an attribute dictionary of type [NSAttributedString.Key : Elk]

Third party libraries:


Live updates with Injection for Xcode


Attribute dictionary


Dictionary test TextAttributes property TextAttribute method
NSFontAttributeName Police Font(Name:Size:)
Writing (_ πŸ™‚
NSParagraphStyleAttributeName paragraphStyle paragraphStyle(_ πŸ™‚
NSForegroundColorAttributeName foreground color foreground color(_ πŸ™‚
foregroundcolor(white:alpha πŸ™‚
foregroundcolor(red:green:blue:alpha πŸ™‚
Foreground color(patternImage πŸ™‚
NSBackgroundColorAttributeName Background color background color(_ πŸ™‚
backgroundcolor(white:alpha πŸ™‚
backgroundcolor(red:green:blue:alpha πŸ™‚
background color(pattern image πŸ™‚
NSLigatureAttributeName Binding Binding(_ πŸ™‚
NSKernAttributeName Core core(_)
NSStrikethroughStyleAttributeName Style type Crossed-out style (_ πŸ™‚
NSStrikethroughColorAttributeName strikethroughColor color blocked(_ πŸ™‚
strike throughColor(white:alpha πŸ™‚
strike throughColor(hue:saturation:brightness:alpha πŸ™‚
strike throughColor(red:green:blue:alpha πŸ™‚
bar color(patternImage πŸ™‚
NSUnderlineStyleAttributeName style of underlining underscore type(_ πŸ™‚
NSUnderlineColorAttributeName underlineColor underscore color(_ πŸ™‚
underscore color(white:alpha πŸ™‚
underscoreColor(hue:saturation:brightness:alpha πŸ™‚
underscore color(red:green:blue:alpha πŸ™‚
underscore color(pattern image πŸ™‚
NSStrokeWidthAttributeName stroke width line width(_ πŸ™‚
NSStrokeColorAttributeName strokeColor strokeColor(_ πŸ™‚
strokeColor(white:alpha πŸ™‚
strokeColor(Hue:Saturation:Lightness:Alpha πŸ™‚
strokeColor(red:green:blue:alpha πŸ™‚
strokeColor(patternImage πŸ™‚
NSShadowAttributeName Shadow Shadow(_)
shadow(color:offset:blurRadius πŸ™‚
NSTextEffectAttributeName textEffect textEffect(_ πŸ™‚
NSAttachmentAttributeName Appendix Appendix (_:)
NSLinkAttributeName Link Reference(_:)
link(string:relativeToURL πŸ™‚
NSBaselineOffsetAttributeName baselineOffset baselineOffset(_ πŸ™‚
NSObliquenessAttributeName Skewed Slant(_)
NSExpansionAttributeName Expansion Expansion(_ πŸ™‚
NSVerticalGlyphFormAttributeName verticalGlyphForm verticalGlyphShape(_ πŸ™‚

Form of paragraph

NSMutableParagraphStyle TextAttributes property TextAttribute method
Alignment Alignment Alignment(_ πŸ™‚
firstLineHeadIndent firstLineHeadIndent firstLineHeadIndent(_ πŸ™‚
headIndent headIndent mainIndent(_ πŸ™‚
tailIndent tailIndent tailIndent(_ πŸ™‚
lineBreakMode lineBreakMode lineBreakMode(_ πŸ™‚
maximum line height maximum line height Maximum Line Height(_ πŸ™‚
Line spacing Line spacing line spacing(_ πŸ™‚
paragraph spacing paragraph spacing ParagraphDistance(_ πŸ™‚
paragraphSpacingBefore paragraphSpacingBefore paragraph space before(_:)
baseWritingDirection baseWritingDirection baseWritingDirection(_ πŸ™‚
lineHeightMultiple lineHeightMultiple lineHeightMultiple(_ πŸ™‚



Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate TextAttributes into your Xcode project with Carthage, specify it in your cartfile:

github delba/TextAttributes

Coconut palms

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

To include TextAttributes in your Xcode project with CocoaPods, specify it in your podfile:

use_frameworks !

pod Text attribute


https://github.com/delba/TextAttributesToday’s blog post will be about my favourite topic — composing attributed strings. And I am happy to announce that I have come up with an easier way to do this.. Read more about nsattributedstring get attributes and let us know what you think.

Frequently Asked Questions

What is attributed string?

The idea of an attributed string is to have one string containing the hidden message for the outside message. The basic idea is that this string is encrypted with a normal string that contains the encrypted string. In a nutshell, the hidden message will be decrypted using the private key and will yield the decrypted message. However, the problem is that the private key should be kept secret, so how do we do it? The HTML5 tag allows authors to place text alongside hyperlinks, and also to direct readers to a new web page. The tag is the simplest and most necessary tag in the HTML5 family; however, its form is not straightforward.

How do you make an attributed string in Swift?

When you are composing an attributed string in your Swift app, it gets a bit frustrating sometimes, as you have to write the attribute string by hand, before creating the string, and then you have to add a hardcoded string at the end of the attributed string, which is kind of frustrating. So I found a simple method to compose the attributed string by adding a newline after the “c” in “c = myString” and then you can use the “greeting” method to create the string. In Swift, you can turn the following string: “My name is Mr. Smith – I teach at RHS – I work at a school – I live in a town – I’m 53 years old” into a string with a few lines of code. You just need to add a very simple attribute to the string and then you can call it an attributed string. The downside of this is that the string cannot have any whitespace inside, which makes it harder to read.

How do you make a string bold in Swift?

Bolding an attribute in a String in swift is done like this: let boldString = “Hello, bold attribute!” // * is the character to be bolded let boldString = “Hello, bold attribute!” // ‘>’ is the character to be bolded let boldString = “Hello, bold attribute!” // ‘<' is the character to be bolded let boldString = "Hello, bold attribute!" // '=' is the character to be bolded let boldString = "Hello, bold attribute!" // '+' is the character to be bolded let boldString = "Hello, bold attribute!" // '+' is NOT the character to be bolded let boldString = "Hello, bold attribute!" // ' Strings are one of the most common and powerful types of data in a program. Most apps and websites interact with strings in some way, but they’re not always easy to read. In this post, we’ll show you how to make strings bold in Swift.

nsattributedstringattributed string objective-cnsattributedstring objective-c examplensattributedstring get attributesappend attributed string swiftnsattributedstring font size,People also search for,Feedback,Privacy settings,How Search works,attributed string with different fonts swift,nsattributedstring,attributed string objective-c,nsattributedstring objective-c example,nsattributedstring get attributes,append attributed string swift,nsattributedstring font size,nsattributedstring underline

You May Also Like

How to choose cross-entropy loss function in Keras?

Inputs: 1) A model. It can be any Keras model. 2) An…

What To Do When The Referenced Account Is Currently Locked Out

If you repeatedly enter a wrong password, Windows may prevent you from…

Conceptual Android audio plugin framework

Audio Plugin Framework for Android There is no widely used audio plugin…

13 Solutions To Fix APC INDEX MISMATCH Error in Windows 10

The blue screen with APC_INDEX_MISMATCH in Windows 10 is mainly due to…