summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs25
1 files changed, 23 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
index 9942623f..8d043bac 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
@@ -82,6 +82,8 @@ namespace Xamarin.Forms.Platform.iOS
UpdateFont();
else if (e.PropertyName == Button.BorderWidthProperty.PropertyName || e.PropertyName == Button.BorderRadiusProperty.PropertyName || e.PropertyName == Button.BorderColorProperty.PropertyName)
UpdateBorder();
+ else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
+ UpdateBackgroundVisibility();
else if (e.PropertyName == Button.ImageProperty.PropertyName)
UpdateImage();
}
@@ -91,6 +93,18 @@ namespace Xamarin.Forms.Platform.iOS
((IButtonController)Element)?.SendClicked();
}
+ void UpdateBackgroundVisibility()
+ {
+ if (Forms.IsiOS7OrNewer)
+ return;
+
+ var model = Element;
+ var shouldDrawImage = model.BackgroundColor == Color.Default;
+
+ foreach (var control in Control.Subviews.Where(sv => !(sv is UILabel)))
+ control.Alpha = shouldDrawImage ? 1.0f : 0.0f;
+ }
+
void UpdateBorder()
{
var uiButton = Control;
@@ -101,6 +115,8 @@ namespace Xamarin.Forms.Platform.iOS
uiButton.Layer.BorderWidth = Math.Max(0f, (float)button.BorderWidth);
uiButton.Layer.CornerRadius = button.BorderRadius;
+
+ UpdateBackgroundVisibility();
}
void UpdateFont()
@@ -126,7 +142,10 @@ namespace Xamarin.Forms.Platform.iOS
UIButton button = Control;
if (button != null && uiimage != null)
{
- button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
+ if (Forms.IsiOS7OrNewer)
+ button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
+ else
+ button.SetImage(uiimage, UIControlState.Normal);
button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
@@ -165,7 +184,9 @@ namespace Xamarin.Forms.Platform.iOS
Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Normal);
Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Highlighted);
Control.SetTitleColor(_buttonTextColorDefaultDisabled, UIControlState.Disabled);
- Control.TintColor = Element.TextColor.ToUIColor();
+
+ if (Forms.IsiOS7OrNewer)
+ Control.TintColor = Element.TextColor.ToUIColor();
}
}