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

时间:2012-07-31 16:15:19

标签: iphone ios

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

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

2 个答案:

答案 0 :(得分:1)

好吧,我有好消息和坏消息。坏消息是,你可能在iOS中遇到了一些软限制,因为Apple从来没有想过有人会想要iPhone中的那么多字体。

好消息(某种程度上)是您可以直接从文件see link加载CGFonts和CTFonts。不好的一点是你必须使用Core Graphics或Core Text进行绘图,因为这些东西不是免费的桥接。

答案 1 :(得分:0)

谢谢你。这很有效。但是,它需要创建新的图层而不是旧图层。

这是完整的代码段

#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];