How to change Picker font colour and size in Xamarin forms?

后端 未结 6 1706
梦如初夏
梦如初夏 2021-01-14 17:01

I\'m new to Xamarin and I\'m currently doing a project in Xamarin Forms PCL.

Is there a way to change the font colour and size of Picker?

  

6条回答
  •  不要未来只要你来
    2021-01-14 18:01

    You will need to write a custom renderer for each platform.

    using System;
    using Project.iOS;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly: ExportRenderer (typeof (Picker), typeof (CustomPickerRenderer))]
    namespace Project.iOS
    {
        public class CustomPickerRenderer : PickerRenderer
        {
            protected override void OnElementChanged (ElementChangedEventArgs e)
            {
                base.OnElementChanged (e);
                if (Control != null) {
                    Control.TextColor = UIKit.UIColor.White;
                }
            }
        }
    }
    

    Here is an example for iOS. This would change the color of the text, you will need to do something similar for Android, and just add your font sizing change as well.

提交回复
热议问题