我使用Core Text显示NSAttributed字符串列。它工作正常。在使用系统字体时,它在模拟器和设备中都不会显示任何延迟。但是,使用自定义字体时,需要更多时间来显示设备中的内容。但在模拟器中,结果很快。更多时间用自定义字体显示NSAttributed字符串
- (void)updateAttributedString
{
// Existing Code
if (self.text != nil)
{
self.attributedString = [[NSMutableAttributedString alloc] initWithString:self.text];
NSRange range = NSMakeRange(0, [self.text length]);
// Regarding Fixed font
// [ self.attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"TAUN_Elango_Abirami" size:20] range:range];//This is my custom font
// Regarding custom Font using below code
if (self.font != nil) {
CTFontRef font = [self createCTFont];
[self.attributedString addAttribute:(NSString *)kCTFontAttributeName
value:(__bridge id)font
range:range];
CFRelease(font);
}
}
}
- (CTFontRef)createCTFont;
{
CTFontRef font = CTFontCreateWithName((CFStringRef)self.fontName, self.pointSize, NULL);
return font;
}
如果我添加的代码下面的行,
[self.attributedString addAttribute:(NSString *)kCTFontAttributeName
value:(__bridge id)font
range:range];
显示归因串是在设备慢。 但是,在模拟器中它很快。如果我不添加那段代码,文本将在模拟器和设备中快速显示。
你的问题是? –
@AlbertRenshaw我需要使用自定义字体,并且希望文本在设备中毫不拖延地显示。缓慢是问题。 – Sharon
如果您使用XCode Instruments的时间分析,它是否指出特定的行?另外,您是否需要使用CoreText,CFStuff和桥接器? – Larme