Düzenle

Aracılığıyla paylaş


UIFont.GetPreferredFontForTextStyle Method

Definition

Overloads

GetPreferredFontForTextStyle(NSString)

Weakly-typed version of an API used to retrieve the user's desired font size.

GetPreferredFontForTextStyle(UIFontTextStyle)

Weakly-typed version of an API used to retrieve the user's desired font size.

GetPreferredFontForTextStyle(NSString, UITraitCollection)

Weakly-typed version of an API used to retrieve the user's desired font size.

GetPreferredFontForTextStyle(UIFontTextStyle, UITraitCollection)

Gets the UIFont that is preferred by the system for and .

GetPreferredFontForTextStyle(NSString)

Weakly-typed version of an API used to retrieve the user's desired font size.

public static UIKit.UIFont GetPreferredFontForTextStyle (Foundation.NSString uiFontTextStyle);
static member GetPreferredFontForTextStyle : Foundation.NSString -> UIKit.UIFont

Parameters

uiFontTextStyle
NSString

Name of one of the built-in system text styles.

Returns

UIFont

Remarks

You can instead use the PreferredBody, PreferredCaption1, PreferredCaption2, PreferredHeadline, PreferredSubheadline properties to get this information.

Using these methods to obtain an initial font during view intiailization is not sufficient to implement dynamic type. After the application user has set the "Text Size Property" in Settings, the application will receive a notification via ObserveContentSizeCategoryChanged. It is the application developer's responsibility, at that point, to invalidate the layout in all view elements that should be resized. The simplest way to do that is to have a method that re-sets the font in all components that support Dynamic Type:

 UIApplication.Notifications.ObserveContentSizeCategoryChanged((s,e) => {
	SetDynamicTypeFonts();
});

//Call this when initializing, and also in response to ObserveContentSizeCategoryChanged notifications
private void SetDynamicTypeFonts()
{
	headlineLabel.Font = UIFont.PreferredFontForTextStyle(UIFontTextStyle.Headline);
	bodyText.Font = UIFont.PreferredFontForTextStyle(UIFontTextStyle.Body);
  //...etc...
}

This can be used from a background thread.

Applies to

GetPreferredFontForTextStyle(UIFontTextStyle)

Weakly-typed version of an API used to retrieve the user's desired font size.

public static UIKit.UIFont GetPreferredFontForTextStyle (UIKit.UIFontTextStyle uiFontTextStyle);
static member GetPreferredFontForTextStyle : UIKit.UIFontTextStyle -> UIKit.UIFont

Parameters

uiFontTextStyle
UIFontTextStyle

The style for which to get the preferred font.

Returns

Remarks

(More documentation for this node is coming)

This can be used from a background thread.

Applies to

GetPreferredFontForTextStyle(NSString, UITraitCollection)

Weakly-typed version of an API used to retrieve the user's desired font size.

public static UIKit.UIFont GetPreferredFontForTextStyle (Foundation.NSString uiFontTextStyle, UIKit.UITraitCollection traitCollection);
static member GetPreferredFontForTextStyle : Foundation.NSString * UIKit.UITraitCollection -> UIKit.UIFont

Parameters

uiFontTextStyle
NSString

The style for which to get the preferred font.

traitCollection
UITraitCollection

The trait collection for which to get the preferred font.

Returns

Remarks

(More documentation for this node is coming)

This can be used from a background thread.

Applies to

GetPreferredFontForTextStyle(UIFontTextStyle, UITraitCollection)

Gets the UIFont that is preferred by the system for and .

public static UIKit.UIFont GetPreferredFontForTextStyle (UIKit.UIFontTextStyle uiFontTextStyle, UIKit.UITraitCollection traitCollection);
static member GetPreferredFontForTextStyle : UIKit.UIFontTextStyle * UIKit.UITraitCollection -> UIKit.UIFont

Parameters

uiFontTextStyle
UIFontTextStyle

The style for which to get the preferred font.

traitCollection
UITraitCollection

The trait collection for which to get the preferred font.

Returns

Remarks

(More documentation for this node is coming)

This can be used from a background thread.

Applies to