Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should take a look at <a href="https://github.com/AliSoftware/OHAttributedLabel" rel="noreferrer">AliSoftware's OHAttributedLabel</a>. It is a subclass of UILabel that draws an NSAttributedString and also provides convenience methods for setting the attributes of an NSAttributedString from UIKit classes.</p> <p>From the sample provided in the repo:</p> <pre><code>#import "NSAttributedString+Attributes.h" #import "OHAttributedLabel.h" /**(1)** Build the NSAttributedString *******/ NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"]; // for those calls we don't specify a range so it affects the whole string [attrStr setFont:[UIFont systemFontOfSize:12]]; [attrStr setTextColor:[UIColor grayColor]]; // now we only change the color of "Hello" [attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)]; /**(2)** Affect the NSAttributedString to the OHAttributedLabel *******/ myAttributedLabel.attributedText = attrStr; // Use the "Justified" alignment myAttributedLabel.textAlignment = UITextAlignmentJustify; // "Hello World!" will be displayed in the label, justified, "Hello" in red and " World!" in gray. </code></pre> <p><strong>Note:</strong> In iOS 6+ you can render attributed strings using the <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html#//apple_ref/occ/instp/UILabel/attributedText" rel="noreferrer">attributedText</a> property of UILabel.</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