summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs99
1 files changed, 99 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
new file mode 100644
index 00000000..f512e157
--- /dev/null
+++ b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
@@ -0,0 +1,99 @@
+using System;
+using System.ComponentModel;
+using System.Drawing;
+using System.Linq;
+#if __UNIFIED__
+using CoreAnimation;
+using CoreGraphics;
+using Foundation;
+using UIKit;
+#else
+using MonoTouch.CoreAnimation;
+using MonoTouch.CoreGraphics;
+using MonoTouch.Foundation;
+using MonoTouch.UIKit;
+#endif
+#if __UNIFIED__
+using RectangleF = CoreGraphics.CGRect;
+using SizeF = CoreGraphics.CGSize;
+using PointF = CoreGraphics.CGPoint;
+
+#else
+using nfloat=System.Single;
+using nint=System.Int32;
+using nuint=System.UInt32;
+#endif
+
+namespace Xamarin.Forms.Platform.iOS
+{
+ public static class ColorExtensions
+ {
+ internal static readonly UIColor Black = UIColor.Black;
+ internal static readonly UIColor SeventyPercentGrey = new UIColor(0.7f, 0.7f, 0.7f, 1);
+
+ public static CGColor ToCGColor(this Color color)
+ {
+ return new CGColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
+ }
+
+ public static Color ToColor(this UIColor color)
+ {
+ nfloat red;
+ nfloat green;
+ nfloat blue;
+ nfloat alpha;
+ color.GetRGBA(out red, out green, out blue, out alpha);
+ return new Color(red, green, blue, alpha);
+ }
+
+ public static UIColor ToUIColor(this Color color)
+ {
+ return new UIColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
+ }
+
+ public static UIColor ToUIColor(this Color color, Color defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor.ToUIColor();
+
+ return color.ToUIColor();
+ }
+
+ public static UIColor ToUIColor(this Color color, UIColor defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor;
+
+ return color.ToUIColor();
+ }
+ }
+
+ public static class PointExtensions
+ {
+ public static Point ToPoint(this PointF point)
+ {
+ return new Point(point.X, point.Y);
+ }
+ }
+
+ public static class SizeExtensions
+ {
+ public static SizeF ToSizeF(this Size size)
+ {
+ return new SizeF((float)size.Width, (float)size.Height);
+ }
+ }
+
+ public static class RectangleExtensions
+ {
+ public static Rectangle ToRectangle(this RectangleF rect)
+ {
+ return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
+ }
+
+ public static RectangleF ToRectangleF(this Rectangle rect)
+ {
+ return new RectangleF((nfloat)rect.X, (nfloat)rect.Y, (nfloat)rect.Width, (nfloat)rect.Height);
+ }
+ }
+} \ No newline at end of file