iOS 6 NSAttributedString: Set Text Underline, Paragraph Styles and Glyph Form – Part 2

In Part 1 of working with attributed strings in iOS 6 I covered how to use foreground and background colors, specify a preferred font, create character strike-through and show a shadow on text. The specific attribute names that were covered follow:

NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSFontAttributeName;

In this post I will cover how to use underline, paragraph and glyph attributes:

NSString *const NSUnderlineStyleAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;
Continue reading

iOS 6 NSAttributedString, Set Text Font, Foreground And Background Colors, StrikeThrough And Shadow – Part 1

Attributed strings make an association between characters and their attributes. Like NSString objects, there are two variations, NSAttributedString and NSMutableAttributedString.

Although previous versions of iOS supported attributed strings, it wasn’t until iOS 6 that controls such as buttons, labels, textfields and textviews defined a property to manage attributes.

Attributes are applied to a range of characters, so you can for example, set a strikethrough attribute for just a portion of a string. It’s also important to note that the default font for attributed string objects is Helvetica 12-point. Keep this in mind if you set the font attribute for a range other than the complete string.

The following attributes can be set with attributed strings:

NSString *const NSFontAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSLigatureAttributeName;
NSString *const NSKernAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSUnderlineStyleAttributeName;
NSString *const NSStrokeColorAttributeName;
NSString *const NSStrokeWidthAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;
Continue reading