Book Image

Application Development in iOS 7

By : Kyle Begeman
Book Image

Application Development in iOS 7

By: Kyle Begeman

Overview of this book

Table of Contents (15 chapters)
Application Development in iOS 7
About the Author
About the Reviewers

Text formatting

With TextKit, we can apply some fairly simple text editing properties to our text. These include bold, italics, and underlined text. In order to do this, we are going to use a brand new class available in iOS 7, UIFontDescriptor. This class is used to describe a font and all of its attributes. Also, more importantly, you are able to directly modify attributes and create a new font. All font attributes are represented by either a dictionary or a key string constant.

Making text bold and italicizing

Let's take a look at a piece of code to see how we can make bold text using UIFontDescriptor:

NSDictionary *currentAttributesDict = [self.textView.textStorage attributesAtIndex:0


UIFont *currentFont = [currentAttributesDict objectForKey:NSFontAttributeName];

UIFontDescriptor *fontDescriptor = [currentFont fontDescriptor];
UIFontDescriptor *changedFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];

UIFont *updatedFont...