From the blog

NSAttributedString Creation Helpers

NSAttributedString is a great addition to the iOS SDK.

Since the release of iOS 6, we are able to use NSAttributedString with UIKit, assigning it to UILabels and  UITextViews. Here is the code for creating this  NSAttributedString: “(middleContent)” (with bold parentheses and italic middle content):

The above example shows that an abundance of code is required to create a very basic string. The inefficiency of Apple’s interface for NSAttributedString leaves a lot to be desired.

Following a similar syntax as NSDictionary’s - (instancetype)initWithObjectsAndKeys:(id)firstObject ... we can simplify this creation.

Read more about the above category for NSAttributedString on GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *