【发布时间】:2021-02-18 08:31:20
【问题描述】:
创建 MyFramework.framework 以共享我在我的应用程序之间显示的视图。目前,我在应用程序“MyApp”中使用 MyFramework。
在我的项目中使用的框架(MyFrawork.framework)中创建了名为 Resources.bundle 的包。
我在那里放了一些图像和字体。我将此捆绑包放在 MyFrawork.framework 内的 复制捆绑包资源 中。
尝试从 MyFramowork.framework 获取窗口时,我的字体和图像未加载...
我想做的是:
NSString *fontName;
static NSBundle* frameworkBundle = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"Resources.bundle"];
frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
});
NSLog(@"[Bundle] IS NULL: %@", frameworkBundle == nil ? @"YES" : @"NO");
NSString *fontPath = [frameworkBundle pathForResource:@"Roboto-Regular" ofType:@"ttf"];
NSData *inData = [NSData dataWithContentsOfFile:fontPath];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
CFErrorRef error;
fontName = (NSString *)CFBridgingRelease(CGFontCopyPostScriptName(font));
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"[FONT]Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
frameworkBundle 总是为零,所以我在日志中总是有“[Bundle] IS NULL: YES”。
以上都是在 MyFrawork.framwork 中完成的。在这里我如何尝试加载我正在使用的字体:
[title setFont:[UIFont fontWithName:fontName size:11]];
如何从 MyFramework.framework 访问 Resource.bundle,以便可以使用其他应用程序中的这些资源?
【问题讨论】:
标签: ios objective-c xcode frameworks ios-frameworks