summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.iOS
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.ControlGallery.iOS
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.ControlGallery.iOS')
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs6
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/CustomRenderer40251.cs60
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj1
3 files changed, 64 insertions, 3 deletions
diff --git a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
index d3107735..1aed7738 100644
--- a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
+++ b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
@@ -205,7 +205,7 @@ namespace Xamarin.Forms.ControlGallery.iOS
sl?.Children.Add(uilabel);
// Create and add a native Button
- var uibutton = new UIButton(UIButtonType.RoundedRect);
+ var uibutton = new UIButton(UIButtonType.System);
uibutton.SetTitle("Toggle Text Amount", UIControlState.Normal);
uibutton.Font = UIFont.FromName("Helvetica", 14f);
@@ -304,7 +304,7 @@ namespace Xamarin.Forms.ControlGallery.iOS
Text = "DefaultText"
};
- var uibuttonColor = new UIButton(UIButtonType.RoundedRect);
+ var uibuttonColor = new UIButton(UIButtonType.System);
uibuttonColor.SetTitle("Toggle Text Color Binding", UIControlState.Normal);
uibuttonColor.Font = UIFont.FromName("Helvetica", 14f);
uibuttonColor.TouchUpInside += (sender, args) => uilabel.TextColor = UIColor.Blue;
@@ -347,7 +347,7 @@ namespace Xamarin.Forms.ControlGallery.iOS
public void StartPressed40911()
{
var loginViewController = new UIViewController { View = { BackgroundColor = UIColor.White } };
- var button = UIButton.FromType(UIButtonType.RoundedRect);
+ var button = UIButton.FromType(UIButtonType.System);
button.SetTitle("Login", UIControlState.Normal);
button.Frame = new CGRect(20, 100, 200, 44);
loginViewController.View.AddSubview(button);
diff --git a/Xamarin.Forms.ControlGallery.iOS/CustomRenderer40251.cs b/Xamarin.Forms.ControlGallery.iOS/CustomRenderer40251.cs
new file mode 100644
index 00000000..19ebbb76
--- /dev/null
+++ b/Xamarin.Forms.ControlGallery.iOS/CustomRenderer40251.cs
@@ -0,0 +1,60 @@
+using UIKit;
+using Xamarin.Forms.Platform.iOS;
+using Xamarin.Forms;
+using System.Collections.Generic;
+using Xamarin.Forms.ControlGallery.iOS;
+using Xamarin.Forms.Controls.Issues;
+
+[assembly: ExportRenderer(typeof(Button), typeof(CustomRenderer40251))]
+namespace Xamarin.Forms.ControlGallery.iOS
+{
+ public class CustomRenderer40251 : ButtonRenderer
+ {
+ Dictionary<string, object> originalValues = new Dictionary<string, object>();
+
+ public CustomRenderer40251()
+ {
+ if (TestPage40251.Arg == "TitleColor")
+ {
+ originalValues.Add("TitleColor", UIButton.Appearance.TitleColor(UIControlState.Normal));
+ UIButton.Appearance.SetTitleColor(UIColor.Red, UIControlState.Normal);
+ }
+ else if (TestPage40251.Arg == "TitleShadowColor")
+ {
+ originalValues.Add("TitleShadowColor", UIButton.Appearance.TitleShadowColor(UIControlState.Normal));
+ UIButton.Appearance.SetTitleShadowColor(UIColor.White, UIControlState.Normal);
+ }
+ else if (TestPage40251.Arg == "BackgroundImage")
+ {
+ originalValues.Add("BackgroundImage", UIButton.Appearance.BackgroundImageForState(UIControlState.Normal));
+ UIButton.Appearance.SetBackgroundImage(new UIImage("Intranet-icon.png"), UIControlState.Normal);
+ }
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.NewElement != null)
+ {
+ if (Control != null)
+ Control.TitleShadowOffset = new CoreGraphics.CGSize(2, 2);
+ }
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ if (TestPage40251.Arg == "TitleColor")
+ UIButton.Appearance.SetTitleColor(originalValues["TitleColor"] as UIColor, UIControlState.Normal);
+ else if (TestPage40251.Arg == "TitleShadowColor")
+ UIButton.Appearance.SetTitleShadowColor(originalValues["TitleShadowColor"] as UIColor, UIControlState.Normal);
+ else if (TestPage40251.Arg == "BackgroundImage")
+ UIButton.Appearance.SetBackgroundImage(originalValues["BackgroundImage"] as UIImage, UIControlState.Normal);
+ }
+
+ base.Dispose(disposing);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
index a601b513..0810383a 100644
--- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
+++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
@@ -160,6 +160,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="BrokenNativeControl.cs" />
+ <Compile Include="CustomRenderer40251.cs" />
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<None Include="app.config" />