我想要一个 UITextView 在两种显示模式之间切换。在模式 1 中,它应该显示缩写,在模式 2 中应该显示完整的单词。例如“Abbr”。与“缩写”。
最好的方法是什么?请记住,某些单词可以具有相同的缩写,并且用户可以自由输入完整的单词或缩写?
到目前为止,我试图继承 NSLayoutManager。假设我得到一个缩写字符串并且我必须绘制完整的单词,我将实现以下方法:
-(void)setGlyphs:(const CGGlyph *)glyphs
properties:(const NSGlyphProperty *)props
characterIndexes:(const NSUInteger *)charIndexes
font:(UIFont *)aFont
forGlyphRange:(NSRange)glyphRange
{
NSUInteger length = glyphRange.length;
NSString *sourceString = @"a very long string as a source of characters for substitution"; //temp.
unichar *characters = malloc(sizeof(unichar) * length+4);
CGGlyph *subGlyphs = malloc(sizeof(CGGlyph) * length+4);
[sourceString getCharacters:characters
range:NSMakeRange(0, length+4)];
CTFontGetGlyphsForCharacters((__bridge CTFontRef)(aFont),
characters,
subGlyphs,
length+4);
[super setGlyphs:subGlyphs
properties:props
characterIndexes:charIndexes
font:aFont
forGlyphRange:NSMakeRange(glyphRange.location, length+4)];
}
但是,当我尝试插入 4 个额外的字形时,此方法会抱怨无效的字形索引“_NSGlyphTreeInsertGlyphs 无效字符索引”。