0

我在我的应用程序中使用Constantia字体系列,regular 粗体斜体样式是我的要求,我面临的问题是,我只能得到常规样式的输出,而不是粗体和斜体,我已经添加了所有三种样式字体进入应用程序,并在Fonts provided by application部分下的 plist 文件中。我尝试了以下

UIFont *bFont = [UIFont fontWithName:@"Constantia-Bold" size:24.0];
UIFont *bFont = [UIFont fontWithName:@"ConstantiaBold" size:24.0];
UIFont *bFont = [UIFont fontWithName:@"Constantia_Bold" size:24.0];

UIFont *iFont = [UIFont fontWithName:@"Constantia-Italic" size:24.0];
UIFont *iFont = [UIFont fontWithName:@"ConstantiaItalic" size:24.0];
UIFont *iFont = [UIFont fontWithName:@"Constantia_Italic" size:24.0];

但没有一个案例有效,只有UIFont *font = [UIFont fontWithName:@"Constantia" size:24.0];一个有效。我知道我只在字体名称中遗漏了一些东西。

我尝试在 Mac 字体的选项中找到字体,我在All Fonts部分(左上角)下得到了这个字体,我发现的一个奇怪的地方是,所有Constantia 粗体斜体regular作为单个名称安装,即Constantia仅。

PS字体可以从这里下载。

4

4 回答 4

3

这是如何在应用程序中添加自定义字体的步骤。

1 - 在您的应用程序中添加.TTF字体
2 - 修改application-info.plist file.
3 - 将“应用程序提供的字体”键添加到新行
4 - 并将每个.TTF文件(字体)添加到每一行。

欲了解更多信息,请阅读网站和网站。

对于粗体

// Equivalent to [UIFont fontWithName:@"FontName-BoldMT" size:17]
UIFont* font = [UIFont fontWithFamilyName:@"FontName" traits:GSBoldFontMask size:17];

和粗体/斜体

UIFont* font = [UIFont fontWithMarkupDescription:@"font-family: FontName; font-size: 17px; font-weight: bold/italic;"]; // set here, either bold/italic.
于 2013-03-11T10:47:08.663 回答
1

以下是如何查看应用程序可用的每种字体的真实名称:

// Log fonts
for (NSString *family in [UIFont familyNames])
{
    NSLog(@"Font family %@:", family);
    for (NSString *font in [UIFont fontNamesForFamilyName:family])
        NSLog("    %@", font);
}
于 2013-03-11T11:03:51.027 回答
0

UPDATE 16 June 2018: application can be rejected, try find another solution

 #import <dlfcn.h>

// includer for font
NSUInteger loadFonts( )
{
    NSUInteger newFontCount = 0;
    NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
    const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];

    if (frameworkPath) 
    {
        void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);

        if (graphicsServices)
        {
            BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");

            if (GSFontAddFromFile)
            {

                BOOL verizon = NO;

                NSLog(@"%@",[[UIDevice currentDevice] machine]);

                if ([[[UIDevice currentDevice] machine] rangeOfString:@"iPhone3,3"].location != NSNotFound) {
                    verizon = YES;
                }

                for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
                {
                    if ([fontFile rangeOfString:@"_"].location != NSNotFound && verizon) {
                        newFontCount += GSFontAddFromFile([fontFile UTF8String]);
                    }

                    if ([fontFile rangeOfString:@"-"].location != NSNotFound && !verizon) {
                        newFontCount += GSFontAddFromFile([fontFile UTF8String]);
                    }

                }
            }
        }
    }

    return newFontCount;
}

I'm using the function usually :enter image description here)

于 2013-03-11T22:10:18.173 回答
-1

我认为IOS中不存在这种类型的字体。请从这里检查http://iosfonts.com/

于 2013-03-11T11:04:27.970 回答