

Label.FontSize = DeviceInfo.Platform = DevicePlatform.iOS ? 20 :ĭeviceInfo.Platform = DevicePlatform.Android ? 22 : 24 Text = "Different font properties on different platforms"
FONT VIEWER SITE CODE
The DeviceInfo.Platform property can be used in code to set font properties per platform: Label label = new Label The example below sets different font families and sizes: The OnPlatform and On classes can be used in XAML to set font properties per platform. For more information, see Display font icons. The equivalent C# code is: Label label = new Labelįont auto scaling also works with font icons.

The FontSize property can be set to a double value: The equivalent C# code is: Label label1 = new LabelįontAttributes = FontAttributes.Bold | FontAttributes.ItalicĬontrols that display text can set the FontSize property to specify the font size. The equivalent C# code is: // Use font nameĬontrols that display text can set the FontAttributes property to specify font attributes: Registered fonts can be consumed by setting the FontFamily property of a control that displays text to the font name, without the file extension: Īlternatively, it can be consumed by referencing its alias: In addition, if you want to include files from sub-folders too, then configure it using additional wildcard characters, for example, Resources\Fonts\**\*. The * wildcard character indicates that all the files within the folder will be treated as being font files. However, in this scenario their build action must be manually set to MauiFont in the Properties window.Īt build time, fonts are copied to your app package. Alternatively, all fonts in the app can be registered by using a wildcard in your project file: įonts can also be added to other folders of your app project. This creates a corresponding entry in your project file. In the example above, the first argument to the AddFont method is the font filename, while the second argument represents an optional alias by which the font can be referenced when consuming it.Ī font can be added to your app project by dragging it into the Resources\Fonts folder of the project, where its build action will automatically be set to MauiFont. Then, on the IFontCollection object, call the AddFont method to add the required font to your app: namespace MyMauiAppįonts.AddFont("Lobster-Regular.ttf", "Lobster") This is accomplished by invoking the ConfigureFonts method on the MauiAppBuilder object.
FONT VIEWER SITE REGISTRATION
True type format (TTF) and open type font (OTF) fonts can be added to your app and referenced by filename or alias, with registration being performed in the CreateMauiApp method in the MauiProgram class. These properties are backed by BindableProperty objects, which means that they can be targets of data bindings, and styled.Īll controls that display text automatically use font scaling, which means that an app's UI reflects text scaling preferences set in the operating system. The default value of this property is true.
