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.
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 effectiveRange:nil]; UIFont *currentFont = [currentAttributesDict objectForKey:NSFontAttributeName]; UIFontDescriptor *fontDescriptor = [currentFont fontDescriptor]; UIFontDescriptor *changedFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont *updatedFont...