Search code examples
iosobjective-cnsattributedstring

Can I set the `attributedText` property of `UILabel`


Can I set the attributedText property of a UILabel object? I tried the below code:

UILabel *label = [[UILabel alloc] init];
label.attributedText = @"asdf";

But it gives this error:

Property "attributedText" not found on object of type 'UILabel *'

#import <CoreText/CoreText.h> not working


Solution

  • Unfortunately, UILabel doesn't support attributed strings. You can use OHAttributedLabel instead.

    Update: Since iOS6, UILabel does support attributed strings. See UILabel reference or Michael Kessler's answer below for more details.