xcode 应用程序提供的字体列表 (iOS)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18298713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:42:50  来源:igfitidea点击:

List of Fonts Provided by Application (iOS)

iosxcodefontsinfo.plist

提问by Wilky94

does anyone know how to get a list of custom fonts from the 'Fonts provided by application' key in the info.plist file in Xcode? Thanks

有谁知道如何从 Xcode 的 info.plist 文件中的“应用程序提供的字体”键中获取自定义字体列表?谢谢

采纳答案by Martin R

The following code reads the list of custom font files from the Info.plist, and extracts the full font name from the font file. (Parts of the code is copied from https://stackoverflow.com/a/17519740/1187415with small modifications and ARC adjustments).

以下代码从 Info.plist 中读取自定义字体文件列表,并从字体文件中提取完整字体名称。(部分代码是从https://stackoverflow.com/a/17519740/1187415复制而来的, 并做了一些小的修改和 ARC 调整)。

Objective-C

目标-C

NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSArray* fontFiles = [infoDict objectForKey:@"UIAppFonts"];

for (NSString *fontFile in fontFiles) {
    NSLog(@"file name: %@", fontFile);
    NSURL *url = [[NSBundle mainBundle] URLForResource:fontFile withExtension:NULL];
    NSData *fontData = [NSData dataWithContentsOfURL:url];
    CGDataProviderRef fontDataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)fontData);
    CGFontRef loadedFont = CGFontCreateWithDataProvider(fontDataProvider);
    NSString *fullName = CFBridgingRelease(CGFontCopyFullName(loadedFont));
    CGFontRelease(loadedFont);
    CGDataProviderRelease(fontDataProvider);
    NSLog(@"font name: %@", fullName);
}

Swift 3 equivalent:

Swift 3 等效项:

if let infoDict = Bundle.main.infoDictionary,
    let fontFiles = infoDict["UIAppFonts"] as? [String] {
    for fontFile in fontFiles {
        print("file name", fontFile)
        if let url = Bundle.main.url(forResource: fontFile, withExtension: nil),
            let fontData = NSData(contentsOf: url), 
            let fontDataProvider = CGDataProvider(data: fontData) {
            let loadedFont = CGFont(fontDataProvider)
            if let fullName = loadedFont.fullName {
                print("font name", fullName)
            }
        }
    }
}

回答by Kepler

You can add your costume font http://www.danielhanly.com/blog/tutorial/including-custom-fonts-in-ios/enter image description hereBut, I don't, know how to get this list, sorry. But, may be you can look on it in IB, in UILabel attributes.

您可以添加您的服装字体http://www.danielhanly.com/blog/tutorial/include-custom-fonts-in-ios/在此处输入图片说明但是,我不知道如何获取此列表,抱歉。但是,您可能可以在 IB 中的 UILabel 属性中查看它。