Can we not convert NSMutableAttributedString
to NSString
?
I have two NSMutableAttributedStrings
and I am appending the 2nd string onto 1st as below:
[string1 appendAttributedString:string2];
Since I have to display string1 on a label I do:
self.label1.text = (NSString *)string1;
I am getting "unrecognized selector sent to instance"
error.
Am I doing anything wrong here? Isn't this the correct way to assign a NSMutableAttributedString
to text property of a label?
A mutable string with associated attributes (such as visual style, hyperlinks, or accessibility data) for portions of its text.
An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string.
Creating an Attributed String from MarkdownUse Markdown syntax to initialize an attributed string with text and attributes. Use a Markdown-syntax string to iniitalize an attributed string with standard or custom attributes.
You can't use a cast to convert an object from one type to another. Use the provided method:
label1.text = [string1 string];
Better yet, use the attributed string:
label1.attributedText = string1
NSAttributtedString
includes a .string
property. From there, you can take NSString
without attributes.
So:
NSAttributtedString* someString; NSString* string = someString.string;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With