kCTSuperscriptAttributeName nie pracuje za korzystanie indeks i górny
Używam tego kodu do wyświetlania indeks dolny i indeks górny w wytwórni, ale to nie działa.
Tworzę kategorię dla NSAttributedString
.
-(void)setSuperscript:(BOOL)isSuperscript range:(NSRange)range {
[self removeAttribute:(NSString *)kCTSuperscriptAttributeName range:range]; // Work around for Apple leak
[self addAttribute:(NSString*)kCTSuperscriptAttributeName value:[NSNumber numberWithInt:(isSuperscript?1:0)] range:range];
}
-(void)setSubscript:(BOOL)isSubscript range:(NSRange)range {
[self removeAttribute:(NSString *)kCTSuperscriptAttributeName range:range]; // Work around for Apple leak
[self addAttribute:(NSString*)kCTSuperscriptAttributeName value:[NSNumber numberWithInt:(isSubscript?-1:0)] range:range];
}
Czy możesz pokazać, jak się nazywasz? – NSCry
http://stackoverflow.com/questions/9284077/how-do-i-include-superscripts-in-nsstring check to – NSCry
Wołam go w następujący sposób: NSMutableAttributedString * attrStr = [NSMutableAttributedString attributedStringWithString: @ "H2O" ]; [attrStr setSubscript: YES zakres: [txt rangeOfString: @ "2"]]; \t \t label1.attributedText = attrStr; –