Note that there are some explanatory texts on larger screens.

plurals
  1. POrange of string does not work correctly whit nsAttributeString
    primarykey
    data
    text
    <p>i'm trying to set a set of Nsattributestring for my primary string. the situation is this:</p> <p>for example i have 3 string like this:</p> <pre><code>card1.contents = @"■■"; card2.contents = @"▲▲▲"; card3.contents = @"■■■"; </code></pre> <p>and the last string like this:</p> <pre><code>matchingString = @"Matched 3 card: ▲▲▲&amp;■■■&amp;▲▲▲ for 80 points" </code></pre> <p>the matchingString value is inside a label. i would try to find the range of substrings in a matchingString, and add an NsAttributeString for etch substring.</p> <p>i'm using this code inside a loop for add the attribute to my label:</p> <pre><code> [self addLableAttributes:@{NSForegroundColorAttributeName: [SetCardGameViewController getUIColorFromColorCard:card.color alphavalue:1], NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)} range:[[self.matchedResulLabel.attributedText string] rangeOfString:card.contents]]; </code></pre> <p>this code doesn't work, when i print the text from label, it don't have any attribute, i have tried to change </p> <p><code>[[self.matchedResulLabel.attributedText string] rangeOfString:card.contents]</code> </p> <p>to </p> <pre><code>range:[[self.matchedResulLabel.attributedText string] rangeOfString:self.matchedResulLabel.text] </code></pre> <p>in this case it works fine, but is not what i need. So i think the problems is in the Range, but e cant fine were .</p> <p>this is the code for the addLableAttributes method:</p> <pre><code> - (void)addLableAttributes:(NSDictionary *)attributes range:(NSRange)range { if (range.location != NSNotFound) { NSMutableAttributedString *mat = [self.matchedResulLabel.attributedText mutableCopy]; [mat addAttributes:attributes range:range]; self.matchedResulLabel.attributedText = mat; } } </code></pre> <p>thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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