Issue
I have changed successfully the color of the Slider on Android creating a Custom Renderer Here the example.
[assembly: ExportRenderer(typeof(CustomSlider), typeof(CustomSliderRenderer))]
namespace ForteMultiplataform.Droid
{
public class CustomSliderRenderer : SliderRenderer
{
public CustomSliderRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
string colorSlider = "#008000";
Control.ProgressDrawable.SetColorFilter(Xamarin.Forms.Color.FromHex(colorSlider).ToAndroid(), PorterDuff.Mode.SrcIn);
// Set Progress bar Thumb color
Control.Thumb.SetColorFilter(
Xamarin.Forms.Color.FromHex(colorSlider).ToAndroid(),
PorterDuff.Mode.SrcIn);
}
}
}
}
How to achieve that for iOS, and UWP?
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
string colorSlider = "#008000";
//What do I put here??
}
}
Solution
iOS Custom Renderer
According to the Apple Docs, UISlider
has three properties for which we'll need to update:
MaximumTrackTintColor
- Specifies the tint color of the track to the leading side of the slider’s thumb. The value defaults to the slider’s inherited tint color. Access this value at runtime with the minimumTrackTintColor property.
MinimumTrackTintColor
- Specifies the tint color of the track to the trailing side of the slider’s thumb. Access this value at runtime with the maximumTrackTintColor property.
ThumbTintColor
- Controls the tint color of the slider’s thumb. Access this value at runtime with the thumbTintColor property
Code
[assembly: ExportRenderer(typeof(CustomSlider), typeof(CustomSliderRenderer))]
namespace CustomSliderColor.iOS
{
public class CustomSliderRenderer : SliderRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (Control != null)
{
const string colorSlider = "#008000";
Control.MaximumTrackTintColor = Color.FromHex(colorSlider).ToUIColor();
Control.MinimumTrackTintColor = Color.FromHex(colorSlider).ToUIColor();
Control.ThumbTintColor = Color.FromHex(colorSlider).ToUIColor();
}
}
}
}
Answered By - Brandon Minnick
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.