How Do I Support Accessibility Font Sizes in Xamarin Forms?

后端 未结 3 1727
故里飘歌
故里飘歌 2020-12-09 05:39

For example, I have a label on my page:

var label = new Label
{
    Text = \"Some text here.\",
    LineBreakMode = LineBreakMode.WordWrap,
    FontSize = De         


        
3条回答
  •  我在风中等你
    2020-12-09 06:38

    Using the info in the answer provided @SushiHangover, I was able to implement the following renderer strategy for iOS:

    Create a renderer for each control that you want to support dynamic text on. In my case, this included Labels, Buttons, and Entrys. The renderers assign the Control.Font to a UIFontDescriptor with the PointSize percentage adjusted based on the NamedSize assigned to the Xamarin Forms control.

    Example:

    [assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
    namespace iOS.Controls
    {
        public class CustomButtonRenderer : ButtonRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs

    You could even dynamically support fixed font sizes this way by taking their percentage value based on the base NamedSize.Default size.

    Example:

    [assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
    namespace iOS.Controls
    {
        public class CustomButtonRenderer : ButtonRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs

    For reference, full implementation examples can be found in this GitHub project.

提交回复
热议问题