using System.ComponentModel; using UIKit; using SizeF = CoreGraphics.CGSize; namespace Xamarin.Forms.Platform.iOS { public class ProgressBarRenderer : ViewRenderer { public override SizeF SizeThatFits(SizeF size) { // progress bar will size itself to be as wide as the request, even if its inifinite // we want the minimum need size var result = base.SizeThatFits(size); return new SizeF(10, result.Height); } protected override void OnElementChanged(ElementChangedEventArgs e) { if (e.NewElement != null) { if (Control == null) SetNativeControl(new UIProgressView(UIProgressViewStyle.Default)); UpdateProgress(); } base.OnElementChanged(e); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == ProgressBar.ProgressProperty.PropertyName) UpdateProgress(); } protected override void SetBackgroundColor(Color color) { base.SetBackgroundColor(color); if (Control == null) return; Control.TrackTintColor = color != Color.Default ? color.ToUIColor() : null; } void UpdateProgress() { Control.Progress = (float)Element.Progress; } } }