NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

Ich versuche, fügen Sie einige fancy text auf einem Etikett, aber ich habe in einige Probleme laufen mit dem NSMutableAttributedString Klasse. Ich war das versuchen, zu erreichen, vier: 1. Ändern der schriftart, 2. Unterstrichen Reihe, 3. Änderung Bereich Farbe, 4. Hochgestellt Bereich.

Diesem code:

- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
    NSMutableAttributedString* display = [[NSMutableAttributedString alloc]
                                          initWithString:@"Hello world!"];
    NSUInteger length = [[display string]length] - 1;

    NSRange wholeRange = NSMakeRange(0, length);
    NSRange helloRange = NSMakeRange(0, 4);
    NSRange worldRange = NSMakeRange(6, length);

    NSFont* monoSpaced = [NSFont fontWithName:@"Menlo" 
                                         size:22.0];

    [display addAttribute:NSFontAttributeName
                    value:monoSpaced
                    range:wholeRange];

    [display addAttribute:NSUnderlineStyleAttributeName 
                    value:[NSNumber numberWithInt:1] 
                    range:helloRange];

    [display addAttribute:NSForegroundColorAttributeName 
                    value:[NSColor greenColor]
                    range:helloRange];

    [display addAttribute:NSSuperscriptAttributeName 
                    value:[NSNumber numberWithInt:1] 
                    range:worldRange];

    //@synthesize textLabel; is in this file.
    [textLabel setAttributedStringValue:display];
}

Gibt mir diese Fehlermeldung:

NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds

Auch, ich habe versucht, Herumspielen mit den Bereichen, aber wurde noch mehr verwirrt, als ich versuchte NSRange worldRange = NSMakeRange(4, 5);. Ich verstehe nicht, warum das erzeugt dieses: Hell^o wor^ld!, wo die Briefe im inneren des ^s, sind hoch.

NSRange worldRange = NSMakeRange(6, 6); erzeugt die gewünschte Wirkung, hello ^world!^.

Was das Etikett sieht wie folgt aus:
NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

InformationsquelleAutor 425nesp | 2012-07-20

Schreibe einen Kommentar