应用程序中的许多字体文件导致无法加载.xib文件



我的iphone应用程序中有600个字体的文件,应用程序找不到包含这600个文件的.xib文件。如果我删除了这600个,.xib文件将被正确加载,不会出现问题。

我检查了应用程序中资源文件数量的限制,但没有。此外,文件的大小只有100MB,这还可以。我不知道问题出在哪里。

好吧,我有好消息也有坏消息。坏消息是,你可能在iOS中达到了一些软限制,因为苹果从未想过有人想要在iPhone中使用这么多字体。

好消息是,您可以直接从文件中加载CGFonts和CTFonts,请参阅链接。糟糕的是,你必须使用核心图形或核心文本进行绘图,因为这些东西不是免费的桥接。

谢谢。这起到了作用。然而,它需要创建新的层来写入,而不是旧的层。。

这是完整的代码片段

#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>

CTFontRef ctfont =  [self newCustomFontWithName:@"cs" ofType:@"ttf" attributes:nil];
CATextLayer *  normalTextLayer_ = [[CATextLayer alloc] init];
normalTextLayer_.font = ctfont;
normalTextLayer_.string = @"alleluja";
normalTextLayer_.wrapped = YES;
normalTextLayer_.foregroundColor = [[UIColor purpleColor] CGColor];
normalTextLayer_.fontSize = 20.f;
normalTextLayer_.alignmentMode = kCAAlignmentCenter;
normalTextLayer_.frame = CGRectMake(0.f, 10.f, 320.f, 32.f);
[self.view.layer addSublayer:normalTextLayer_];    

CTFontRef cttFont =  [self newCustomFontWithName:@"cs" ofType:@"ttf" attributes:nil];
NSString *fontName = [(NSString *)CTFontCopyName(cttFont, kCTFontPostScriptNameKey) autorelease];
CGFloat fontSize = CTFontGetSize(cttFont);
NSLog(@"%f fontName = '%@'",fontSize,fontName);
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
UITextView * xx = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
xx.text = @"alleluja";
xx.font = font;

[self.view addSubview:xx];

最新更新