Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think, it is a very convenient way to use <code>regular expressions</code> to find a range for applying attributes. This is how I did it: </p> <pre><code>NSMutableAttributedString *goodText = [[NSMutableAttributedString alloc] initWithString:articleText]; NSRange range = [articleText rangeOfString:@"\\[.+?\\]" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch]; if (range.location != NSNotFound) { [goodText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Georgia" size:16] range:range]; [goodText addAttribute:NSForegroundColorAttributeName value:[UIColor brownColor] range:range]; } NSString *regEx = [NSString stringWithFormat:@"%@.+?\\s", [self.article.titleText substringToIndex:0]]; range = [articleText rangeOfString:regEx options:NSRegularExpressionSearch|NSCaseInsensitiveSearch]; if (range.location != NSNotFound) { [goodText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Georgia-Bold" size:20] range:range]; [goodText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range]; } [self.textView setAttributedText:goodText]; </code></pre> <p>I was searching for a list of available attributes and didn't find them here and in a class reference's first page. So I decided to post here information on that. </p> <p><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAttributedString_AppKitAdditions/Reference/Reference.html#//apple_ref/doc/uid/20000167">Standard Attributes</a></p> <p>Attributed strings support the following standard attributes for text. If the key is not in the dictionary, then use the default values described below.</p> <pre><code>NSString *NSFontAttributeName; NSString *NSParagraphStyleAttributeName; NSString *NSForegroundColorAttributeName; NSString *NSUnderlineStyleAttributeName; NSString *NSSuperscriptAttributeName; NSString *NSBackgroundColorAttributeName; NSString *NSAttachmentAttributeName; NSString *NSLigatureAttributeName; NSString *NSBaselineOffsetAttributeName; NSString *NSKernAttributeName; NSString *NSLinkAttributeName; NSString *NSStrokeWidthAttributeName; NSString *NSStrokeColorAttributeName; NSString *NSUnderlineColorAttributeName; NSString *NSStrikethroughStyleAttributeName; NSString *NSStrikethroughColorAttributeName; NSString *NSShadowAttributeName; NSString *NSObliquenessAttributeName; NSString *NSExpansionAttributeName; NSString *NSCursorAttributeName; NSString *NSToolTipAttributeName; NSString *NSMarkedClauseSegmentAttributeName; NSString *NSWritingDirectionAttributeName; NSString *NSVerticalGlyphFormAttributeName; NSString *NSTextAlternativesAttributeName; </code></pre> <p><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/AttributedStrings/AttributedStrings.html#//apple_ref/doc/uid/10000036i">NSAttributedString programming guide</a></p> <p>A full class reference is <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/Reference/Reference.html">here</a>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload