UIFont && UIFontDescriptor

UIFont

先读一下 API 简单介绍

The UIFont class provides the interface for getting and setting font information. The class provides you with access to the font’s characteristics and also provides the system with access to the font’s glyph information, which is used during layout. You use font objects by passing them to methods that accept them as a parameter.

You do not create UIFont objects using the alloc and init methods. Instead, you use class methods of UIFont, such as preferredFontForTextStyle:, to look up and retrieve the desired font object. These methods check for an existing font object with the specified characteristics and return it if it exists. Otherwise, they create a new font object based on the desired font characteristics.

Font objects are immutable and so it is safe to use them from multiple threads in your app.

译文:

UIFont类提供了获取和设置字体的接口信息。类提供了访问字体的特点,也为系统提供了访问字体的字形信息,用于在布局。你使用字体对象通过他们接受他们作为参数的方法。

你不使用分配和init方法创建UIFont对象。相反,您使用UIFont类方法,如preferredFontForTextStyle:查找和检索所需的字体对象。这些方法检查现有字体对象指定的特色并返回它如果它存在。否则,他们创建一个新的字体对象基于所需的字体特征。

字体对象是不可变的,所以它的使用是安全的,它们在你的应用程序从多个线程。


UIFontDescriptor

UIFontDescriptor objects provide a mechanism to describe a font with a dictionary of attributes. This font descriptor can be used later to create or modify a UIFont object. Font descriptors can be archived and unarchived. Font descriptors have a font matching capability, so that you can partially describe a font by creating a font descriptor with, for example, just a family name. You can then find all the available fonts on the system with a matching family name using matchingFontDescriptorsWithMandatoryKeys:.

There are several ways to create a new UIFontDescriptor object. To take advantage of text styles and respect the user’s current content size category, use preferredFontDescriptorWithTextStyle:. You can also use alloc and initWithFontAttributes:, fontDescriptorWithFontAttributes:, fontDescriptorWithName:matrix:, or fontDescriptorWithName:size: to create a font descriptor based on either your custom attributes dictionary or on a specific font’s name and size. Alternatively you can use one of the fontDescriptor… instance methods (such as fontDescriptorWithFace:) to create a modified version of an existing descriptor (the receiver). The latter methods are useful if you have an existing descriptor and simply want to change one aspect.

All attributes in the attributes dictionary are optional.

译文:

UIFontDescriptor对象提供一种机制来描述字体属性的字典。可以使用此字体描述符后,创建或修改一个UIFont对象。字体描述符可以存档,从未归档。字体描述符有字体匹配功能,您可以通过创建一个部分描述的字体字体描述符,例如,只是一个姓。然后你可以找到系统上所有可用的字体匹配使用matchingFontDescriptorsWithMandatoryKeys姓:。

有几种方法可以创建一个新的UIFontDescriptor对象。利用文本风格和尊重用户的当前内容大小类别,使用preferredFontDescriptorWithTextStyle:。您还可以使用alloc,initWithFontAttributes:,fontDescriptorWithName:矩阵:fontDescriptorWithFontAttributes:或fontDescriptorWithName:大小:创建一个字体描述符根据您的自定义属性字典或特定的字体的名称和大小。或者你可以用一个fontDescriptor…实例方法(如fontDescriptorWithFace:)来创建一个修改版的现有描述符(接收器)。后者的方法是有用的,如果你有一个现有的描述符,只是想改变一个方面。

属性字典中的所有属性都是可选的。



例如:


    _centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(115, 12, 85, 21)];

    _centerLabel.text = @"哈哈哈哈哈哈it's a test!~";

    [_centerLabel setFont:[UIFont fontWithName:@"Helvetica" size:17.0]];

    [self.view addSubview:_centerLabel];


下面两个函数创建字体:

+fontWithName:(NSString *)fontName   size:(CGFloat) fontSize   创建并且返回一个指定字体类型和大小的字体对象,fontName指定字体集的名字和风格(例如宋体,楷书等这一类型的),fontsize设置字体的大小。

-fontWithSize:返回字体的大小

上面我们提到我们需要设置字体集,在IOS系统中我们用到的字体包含一下几种 :

Font Family: American Typewriter( AmericanTypewriter,AmericanTypewriter-Bold)
Font Family: AppleGothic(AppleGothic)
Font Family: Arial(ArialMT,Arial-BoldMT,Arial-BoldItalicMT,Arial-ItalicMT)
Font Family: Arial Rounded MT Bold(ArialRoundedMTBold)
Font Family: Arial Unicode MS(ArialUnicodeMS)
Font Family: Courier(Courier,Courier-BoldOblique,Courier-Oblique,Courier-Bold)
Font Family: Courier New(CourierNewPS-BoldMT,CourierNewPS-ItalicMT,CourierNewPS-BoldItalicMT,CourierNewPSMT)
Font Family: DB LCD Temp (DBLCDTempBlack)
Font Family: Georgia( Georgia-Bold, Georgia,Georgia-BoldItalic,Georgia-Italic)
Font Family: Helvetica(Helvetica-Oblique,Helvetica-BoldOblique,Helvetica,Helvetica-Bold)            默认字体
Font Family: Helvetica Neue(HelveticaNeue,HelveticaNeue-Bold)
Font Family: Hiragino Kaku Gothic **** W3(HiraKakuProN-W3)
Font Family: Hiragino Kaku Gothic **** W6(HiraKakuProN-W6)
Font Family: Marker Felt( MarkerFelt-Thin)
Font Family: STHeiti J  (STHeitiJ-Medium,STHeitiJ-Light)
Font Family: STHeiti K( STHeitiK-Medium, STHeitiK-Light)
Font Family: STHeiti SC(STHeitiSC-Medium, STHeitiSC-Light)
Font Family: STHeiti TC(STHeitiTC-Light,STHeitiTC-Medium)
Font Family: Times New Roman(TimesNewRomanPSMT,TimesNewRomanPS-BoldMT, TimesNewRomanPS-BoldItalicMT, TimesNewRomanPS-ItalicMT)
Font Family: Trebuchet MS( TrebuchetMS-Italic,TrebuchetMS,Trebuchet-BoldItalic,TrebuchetMS-Bold)
Font Family: Verdana( Verdana-Bold,Verdana-BoldItalic, Verdana,Verdana-Italic)
Font Family: Zapfino( Zapfino)

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize    使用标准的接口返回指定大小的字体对象。
+ (CGFloat)systemFontSize    返回标准的系统字体大小。
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize   返回字体对象使用了标准接口来指定字体大小附加黑体风格。

+ (CGFloat)buttonFontSize 返回按钮使用标准字体。

+ (NSArray *)familyNames  返回系统可用字体集名称的数组。一个NSString型数组对象。每一个元素包含了字型集名称。字型集的名称相当于字型的基础名称。如 Times New Roman.你可以输入返回的字符串到 fontNamesForFamilyName: 方法来取得可用的字型集的名称。然後你可以用这些恰当的名称去取得字体对象。

+ (NSArray *)fontNamesForFamilyName:(NSString *)familyName                      )familyName字体集的名称。使用 familyNames 方法取得系统中的一个字体集的名称。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值