Skip to content

Lightweight inline formatting (*bold*, /italic/, etc.) for NSAttributedString

Notifications You must be signed in to change notification settings

jawj/NSMutableAttributedString-InlineStyles

Repository files navigation

NSMutableAttributedString+InlineStyles

Simple inline formatting for NSMutableAttributedString in one screenful of code.

Applies *bold*, /italic/, _underline_, -strikethrough-, ^superscript^ and ~subscript~ styles.
Handles */nested/* and *overlapping /styles* properly/.

Ideal for displaying the odd UILabel with bold or italic sections. If you want a complete Markdown or Textile implementation, that's available (with considerable extra heft) elsewhere.

Example

To produce this:

Example image

Code like this:

UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.attributedText = [NSMAString withString:@"Applies *bold*, /italic/, _underline_, -strikethrough-,\n"
                                               "^superscript^ and ~subscript~ styles.\n"
                                               "Handles */nested/* and *overlapping /styles* properly/."
                                 fontBaseName:@"AvenirNext"
                                      andSize:14.0f];
[label sizeToFit];

Tip

Save wear on your fingers (and make the above example work) by including the following in YourProject-Prefix.pch:

#define NSMAString NSMutableAttributedString

Licence

MIT

About

Lightweight inline formatting (*bold*, /italic/, etc.) for NSAttributedString

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published