在iOS上排列小字体的字体

在iOS上排列小字体的字体,第1张

概述在iOS上,我通过将其文件名(.otf文件)添加到info.plist文件中,然后使用以下代码行,在我的项目中加载自定义字体: UIFont myFont * = [UIFont fontWithName:titleFontName size:titleFontSize]; 我获得了我可以在UILabels和UITextViews中使用的字体. 我如何获得这种字体只显示在小帽子?如果我在Photo 在iOS上,我通过将其文件名(.otf文件)添加到info.pList文件中,然后使用以下代码行,在我的项目中加载自定义字体:

UIFont myFont * = [UIFont FontWithname:TitleFontname size:TitleFontSize];

我获得了我可以在UILabels和UITextVIEws中使用的字体.

我如何获得这种字体只显示在小帽子?如果我在Photoshop中使用它,可以打开小帽开关让所有的单词都以小帽子排版(因此我得出结论,字体中没有任何内容).如何在iOS上获得类似的效果?

将我的字符串转换为大写不是其他原因的可行选项.

更多信息:该字体在其家庭中只有一个成员,通过使用以下代码可以理解,家庭中没有独立的小帽子成员.

for (Nsstring * familyname in [UIFont familynames]) {        NSLog(@"---------------- %@ ---------------",familyname);        for (Nsstring * Fontname in[UIFont FontnamesForFamilyname:familyname] )           NSLog(@"- %@",Fontname);   }
解决方法 通过打开类型功能在字体中启用小帽.在iOS 7中,我们可以使用字体描述符来访问开放类型的功能并启用小帽子.

This question进入如何使用核心文本打开小帽,但是对于UIFonts和UIKit视图也可以轻松实现.您将需要创建一个UIFontDescriptor,并将UIFontDescriptorFeaturesettingsAttribute设置为您要启用的功能的字典数组.

每个字体特征字典包含一个键和值,以指定要素类型,以及功能选择器的键和值.根据您使用的字体,您需要找到对应于小盖帽的正确值.您可以在数组中找到注释部分记录的内容.

UIFont类别

此类别将生成启用小帽的UIFont对象.您需要添加正确的字体名称.

#import "UIFont+SmallCaps.h"#import <CoreText/CoreText.h>@implementation UIFont (SmallCaps)+ (UIFont *) applicationSmallCapsFontWithSize:(CGfloat) size {    /*    // Use this to log all of the propertIEs for a particular Font    UIFont *Font = [UIFont FontWithname: Fontname size: FontSize];    CFArrayRef  FontPropertIEs  =  CTFontcopyFeatures ( ( __brIDge CTFontRef ) Font ) ;    NSLog(@"propertIEs = %@",FontPropertIEs);    */    NSArray *FontFeaturesettings = @[ @{ UIFontFeatureTypeIDentifIErKey: @(kLowerCaseType),UIFontFeatureSelectorIDentifIErKey : @(kLowerCaseSmallCapsSelector) } ];    NSDictionary *FontAttributes = @{ UIFontDescriptorFeaturesettingsAttribute: FontFeaturesettings,UIFontDescriptorNameattribute: Font_name } ;    UIFontDescriptor *FontDescriptor = [ [UIFontDescriptor alloc] initWithFontAttributes: FontAttributes ];    return [UIFont FontWithDescriptor:FontDescriptor size:size];}@end
总结

以上是内存溢出为你收集整理的在iOS上排列小字体的字体全部内容,希望文章能够帮你解决在iOS上排列小字体的字体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1095669.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存