Hello,
I'm trying to change the color of a Picker using a custom renderer. This is what I have.
using System;
using Xamarin.Forms.Platform.iOS;
using AppNamespace;
using Xamarin.Forms;
using AppNamespace.iOS;
using UIKit;
[assembly: ExportRenderer(typeof(CustomPicker), typeof(CustomPickerRenderer))]
namespace AppNamespace.iOS
{
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged (e);
if (this.Control == null) return;
Control.TextColor = UIColor.White;
Control.TextAlignment = UITextAlignment.Center;
}
}
}
I then created the widget like this:
var picker = new CustomPicker {
Title = "Select another one...",
BackgroundColor = Constants.DefaultColor.WithLuminosity(.4f),
HorizontalOptions = LayoutOptions.FillAndExpand,
};
My problem is, even when the Background Color is successfully set up, I can't achieve to change the text color of the "Select another one..." text. I tried using Control.TextColor
and Control.TintColor
but both of them are not working.
Another thing I don't know how to do is to add padding. The Picker
class doesn't have a Padding
property, but I assume I can use the custom renderer to gave it the necessary padding.
Any hints?
EDIT: According to the custom renderer, the Picker
is just a UITextField
. I've checked it out and tried looking for some sort of placeholder color but I can't seem to find any "color" option there.
EDIT 2: The text alignment attribute works just fine.