Ga naar hoofdinhoud
Logo Appt Light

Scale text on Xamarin

Apps should scale text to the size specified by users in the system settings. This is especially important for visually impaired users because they might not be able to read the text otherwise.

Binnen Xamarin Forms kun je styles maken voor schaalbare lettertypes in je app.

Ten eerste moet accessibility scaling worden ingeschakeld voor lettergroottes. Dit kan je doen door True mee e geven aan de SetEnableAccessibilityScalingForNamedFontSizes methode van de Application. Je kunt dit oo in XAML instellen via de eigenschap ios:Application.EnableAccessibilityScalingForNamedFontSizes="true".

Vervolgens moet je het lettertype en de eigenschappen ervan registreren bij de assembly. Daarna kun je de lettertypen in je app gebruiken, ze worden automatisch geschaald op basis van de tekstgrootte voorkeur van de gebruiker.

Je kunt nog meer informatie vinden in de volgende artikelen: Understand named font sizesNamed font size scaling en Dynamic Styles.

using Xamarin.Forms;

[assembly: ExportFont("Lobster-Regular.ttf", Alias="Lobster")]
[assembly: ExportFont("Lobster-Bold.ttf", Alias="LobsterBold")]

namespace Project
{
    public partial class App : Xamarin.Forms.Application
    {
        On<Xamarin.Forms.PlatformConfiguration.iOS>().SetEnableAccessibilityScalingForNamedFontSizes(true);
    }
}
Bijdragen

Feedback?

Laat 't ons weten!