Search code examples
iosobjective-cnsstringnsmutableattributedstring

-[__NSCFString _getValue:forType:]: unrecognized selector sent to instance


NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:timeString];
    UIFont *font = [UIFont fontWithName:self.txtFieldForEndTime.font.familyName size:self.txtFieldForEndTime.font.pointSize / 2];

    NSDictionary *attrs = @{
                            NSFontAttributeName:font,
                            (__bridge NSString *)  kCTSuperscriptAttributeName:[string substringFromIndex:string.length - 2]
                            };
    [attString setAttributes:attrs range:[string rangeOfString:@"PM"]];

The above code is trying to super script the last two AM / PM characters.

But the app is crashing by stating -[__NSCFString _getValue:forType:]: unrecognized selector sent to instance.

Can you please let me know what is wrong with this code. If you have working code which superscripts a part of NSString please let me know.


Solution

  • You can fake superscript by reducing the point size of the font, and use the NSBaselineOffsetAttributeName attribute to move the text up or down the baseline.