summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2017-03-20 10:53:54 -0500
committerRui Marinho <me@ruimarinho.net>2017-03-20 15:53:54 +0000
commitea4673c8cb3e9155a86abc7e8ae49655ee765d3b (patch)
tree776723057e8147aec2a19b0fc14d156ef0b7976c /Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
parent04d034057c9743712d826c290bf9b1f2a0dd7924 (diff)
downloadxamarin-forms-ea4673c8cb3e9155a86abc7e8ae49655ee765d3b.tar.gz
xamarin-forms-ea4673c8cb3e9155a86abc7e8ae49655ee765d3b.tar.bz2
xamarin-forms-ea4673c8cb3e9155a86abc7e8ae49655ee765d3b.zip
[iOS] Use UIButtonType.System for Button and utilize UIButton.Appearance (#554)
* Change button style and use UIButton appearance * added sample code * change references * setting other properties * add comment * refactor proxy setter * made control states array static * remove category declaration * changes * add sample code * changes * Fix identation * Update ButtonRenderer.cs
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs24
1 files changed, 17 insertions, 7 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
index dbdcb241..dd25e635 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
@@ -23,6 +23,8 @@ namespace Xamarin.Forms.Platform.iOS
// but under iOS that suggestion won't work
readonly nfloat _minimumButtonHeight = 44; // Apple docs
+ static readonly UIControlState[] s_controlStates = { UIControlState.Normal, UIControlState.Highlighted, UIControlState.Disabled };
+
public override SizeF SizeThatFits(SizeF size)
{
var result = base.SizeThatFits(size);
@@ -54,10 +56,12 @@ namespace Xamarin.Forms.Platform.iOS
{
if (Control == null)
{
- SetNativeControl(new UIButton(UIButtonType.RoundedRect));
+ SetNativeControl(new UIButton(UIButtonType.System));
Debug.Assert(Control != null, "Control != null");
+ SetControlPropertiesFromProxy();
+
_buttonTextColorDefaultNormal = Control.TitleColor(UIControlState.Normal);
_buttonTextColorDefaultHighlighted = Control.TitleColor(UIControlState.Highlighted);
_buttonTextColorDefaultDisabled = Control.TitleColor(UIControlState.Disabled);
@@ -89,7 +93,7 @@ namespace Xamarin.Forms.Platform.iOS
else if (e.PropertyName == Button.ImageProperty.PropertyName)
UpdateImage();
}
-
+
protected override void SetAccessibilityLabel()
{
// If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Title,
@@ -104,6 +108,16 @@ namespace Xamarin.Forms.Platform.iOS
base.SetAccessibilityLabel();
}
+
+ void SetControlPropertiesFromProxy()
+ {
+ foreach (UIControlState uiControlState in s_controlStates)
+ {
+ Control.SetTitleColor(UIButton.Appearance.TitleColor(uiControlState), uiControlState); // if new values are null, old values are preserved.
+ Control.SetTitleShadowColor(UIButton.Appearance.TitleShadowColor(uiControlState), uiControlState);
+ Control.SetBackgroundImage(UIButton.Appearance.BackgroundImageForState(uiControlState), uiControlState);
+ }
+ }
void OnButtonTouchUpInside(object sender, EventArgs eventArgs)
{
@@ -198,9 +212,7 @@ namespace Xamarin.Forms.Platform.iOS
void ClearEdgeInsets(UIButton button)
{
if (button == null)
- {
return;
- }
Control.ImageEdgeInsets = new UIEdgeInsets(0, 0, 0, 0);
Control.TitleEdgeInsets = new UIEdgeInsets(0, 0, 0, 0);
@@ -210,9 +222,7 @@ namespace Xamarin.Forms.Platform.iOS
void ComputeEdgeInsets(UIButton button, Button.ButtonContentLayout layout)
{
if (button?.ImageView?.Image == null || string.IsNullOrEmpty(button.TitleLabel?.Text))
- {
return;
- }
var position = layout.Position;
var spacing = (nfloat)(layout.Spacing / 2);
@@ -264,4 +274,4 @@ namespace Xamarin.Forms.Platform.iOS
button.TitleEdgeInsets = new UIEdgeInsets(titleVertOffset, -horizontalTitleOffset, -titleVertOffset, horizontalTitleOffset);
}
}
-} \ No newline at end of file
+}