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

Syntax

[Foundation.Export("preferredFontForTextStyle:")]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_7_0)]
public static UIFont GetPreferredFontForTextStyle (Foundation.NSString uiFontTextStyle)

Parameters

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

Returns

UIFont

Remarks

You can instead use the UIFont.PreferredBody, UIFont.PreferredCaption1, UIFont.PreferredCaption2, UIFont.PreferredHeadline, UIFont.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 UIApplication.Notifications.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:

C# Example

 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.

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0