UIFont 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
UIKit 类的字体表示形式。
[Foundation.Register("UIFont", true)]
public class UIFont : Foundation.NSObject, Foundation.INSCopying, Foundation.INSSecureCoding, IDisposable
[<Foundation.Register("UIFont", true)>]
type UIFont = class
inherit NSObject
interface INSCoding
interface INativeObject
interface IDisposable
interface INSCopying
interface INSSecureCoding
- 继承
- 特性
- 实现
注解
UIFont 对象不会直接实例化,而是从此类上的静态方法创建。 可以使用属性PreferredBodyPreferredCaption1PreferredCaption2PreferredHeadlinePreferredSubheadline获取相应用例的首选系统字体。
使用静态 FromName(String, NFloat) 方法创建新的特定字体。
可以使用该 FamilyNames 属性获取所有可用系列名称的列表,然后 FontNamesForFamilyName(String) 获取特定字体系列中可用的字体列表的方法。
系统信息和字体
若要获取表示系统字体的普通、斜体或粗体字体,请使用静态方法 SystemFontOfSize(NFloat, UIFontWeight), ItalicSystemFontOfSize(NFloat) 以及 BoldSystemFontOfSize(NFloat)。
激活版式功能
可以使用字体描述符基于现有字体实例检索新字体。 为此,请从字体中提取不可变 FontDescriptor 属性,并使用它创建具有所需更改的新字体描述符,然后可以使用该描述符传递给 FromDescriptor(UIFontDescriptor, NFloat) 方法来创建更改的字体。
以下示例演示如何更改现有字体,以启用比例数字的 CoreText 版式功能,并使用字符替代方法:
UIFont CustomizeFont (UIFont font)
{
var originalDescriptor = font.FontDescriptor;
// This font has a character alternative, at index 1, use that:
const int characterAlternative = 1;
var attributes = new UIFontAttributes (
new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers),
new UIFontFeature (characterAlternative));
var newDesc = originalDescriptor.CreateWithAttributes (attributes);
return UIFont.FromDescriptor (newDesc, 80);
}
限制字体的字符覆盖率
以下示例通过更改字体支持的字符集来更改字体描述符,并强制系统使用系统中回退字体列表中的字形。 例如,如果要使用 Menlo 字体,以下示例将删除使用梅隆雪人字符(在 Unicode 0x2603),然后回退到系统雪人:
var label = new UILabel (new CGRect (0, 300, 200, 100)) {
Text = "Hello \u2603 there!",
TextColor = UIColor.White,
Font = MyFonts.Menlo
};
var originalDescriptor = label.Font.FontDescriptor;
var originalCharSet = originalDescriptor.CharacterSet;
// Make a copy of the character set to modify
var charSetCopy = originalCharSet.MutableCopy () as NSMutableCharacterSet;
// Remove the snowman
charSetCopy.RemoveCharacters (new NSRange (0x2603, 1));
// Create new descriptor
var removedSnowmanDescriptor = originalDescriptor.CreateWithAttributes (new UIFontAttributes () {
CharacterSet = originalCharSet
});
// Create the font and set it on our label
label.Font = UIFont.FromDescriptor (removedSnowmanDescriptor, 0);
此类的成员可以从后台线程使用。
构造函数
| 名称 | 说明 |
|---|---|
| UIFont(NativeHandle) |
创建非托管对象的托管表示形式时使用的构造函数。 由运行时调用。 |
| UIFont(NSCoder) |
一个构造函数,用于从存储在 unarchiver 对象中的数据初始化对象。 |
| UIFont(NSObjectFlag) |
要调用派生类的构造函数,以跳过初始化,并仅分配对象。 |
属性
| 名称 | 说明 |
|---|---|
| AccessibilityAttributedUserInputLabels |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| AccessibilityRespondsToUserInteraction |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| AccessibilityTextualContext |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| AccessibilityUserInputLabels |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| Ascender |
UIKit 类的字体表示形式。 |
| ButtonFontSize |
UIKit 类的字体表示形式。 |
| CapHeight |
UIKit 类的字体表示形式。 |
| Class |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| ClassHandle |
此类的 Objective-C 类句柄。 |
| DebugDescription |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| Descender |
UIKit 类的字体表示形式。 |
| Description |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| FamilyName |
UIKit 类的字体表示形式。 |
| FamilyNames |
UIKit 类的字体表示形式。 |
| FontDescriptor |
UIKit 类的字体表示形式。 |
| Handle |
处理(指针)到非托管对象表示形式。 (继承自 NSObject) |
| IsDirectBinding |
获取或设置一个值,该值指示此实例是否使用直接 Objective-C 绑定。 (继承自 NSObject) |
| IsProxy |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| LabelFontSize |
UIKit 类的字体表示形式。 |
| Leading |
UIKit 类的字体表示形式。 |
| LineHeight |
UIKit 类的字体表示形式。 |
| Name |
UIKit 类的字体表示形式。 |
| PointSize |
UIKit 类的字体表示形式。 |
| PreferredBody |
正文文本样式的首选 UIFont 。 |
| PreferredCallout |
标注文本样式的首选 UIFont 。 |
| PreferredCaption1 |
Caption1 文本样式的首选 UIFont 。 |
| PreferredCaption2 |
Caption2 文本样式的首选 UIFont 。 |
| PreferredFootnote |
脚注文本样式的首选 UIFont 。 |
| PreferredHeadline |
标题文本样式的首选 UIFont 。 |
| PreferredSubheadline |
子标题文本样式的首选 UIFont 。 |
| PreferredTitle1 |
Title1 文本样式的首选 UIFont 。 |
| PreferredTitle2 |
Title2 文本样式的首选 UIFont 。 |
| PreferredTitle3 |
Title3 文本样式的首选 UIFont 。 |
| RetainCount |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| Self |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| SmallSystemFontSize |
UIKit 类的字体表示形式。 |
| Superclass |
UIKit 类的字体表示形式。 (继承自 NSObject) |
| SuperHandle |
已过时.
用于表示此 NSObject基类中方法的句柄。 (继承自 NSObject) |
| SystemFontSize |
UIKit 类的字体表示形式。 |
| xHeight |
已过时.
小写“x”的大小,以磅为单位。 |
| XHeight |
UIKit 类的字体表示形式。 |
| Zone |
UIKit 类的字体表示形式。 (继承自 NSObject) |
方法
运算符
| 名称 | 说明 |
|---|---|
| Equality(UIFont, UIFont) |
比较两个 UIFont 对象的值相等性。 |
| Inequality(UIFont, UIFont) |
比较两个 UIFont 对象的值不相等。 |