summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs47
1 files changed, 45 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
index bb4342a..2b8b910 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
@@ -1,16 +1,27 @@
using System;
using CoreGraphics;
-using UIKit;
using PointF = CoreGraphics.CGPoint;
using RectangleF = CoreGraphics.CGRect;
using SizeF = CoreGraphics.CGSize;
-
+#if __MOBILE__
+using UIKit;
namespace Xamarin.Forms.Platform.iOS
+#else
+using AppKit;
+using UIColor = AppKit.NSColor;
+
+namespace Xamarin.Forms.Platform.MacOS
+#endif
{
public static class ColorExtensions
{
+#if __MOBILE__
internal static readonly UIColor Black = UIColor.Black;
internal static readonly UIColor SeventyPercentGrey = new UIColor(0.7f, 0.7f, 0.7f, 1);
+#else
+ internal static readonly NSColor Black = NSColor.Black;
+ internal static readonly NSColor SeventyPercentGrey = NSColor.FromRgba(0.7f, 0.7f, 0.7f, 1);
+#endif
public static CGColor ToCGColor(this Color color)
{
@@ -23,10 +34,15 @@ namespace Xamarin.Forms.Platform.iOS
nfloat green;
nfloat blue;
nfloat alpha;
+#if __MOBILE__
color.GetRGBA(out red, out green, out blue, out alpha);
+#else
+ color.GetRgba(out red, out green, out blue, out alpha);
+#endif
return new Color(red, green, blue, alpha);
}
+#if __MOBILE__
public static UIColor ToUIColor(this Color color)
{
return new UIColor((float)color.R, (float)color.G, (float)color.B, (float)color.A);
@@ -47,6 +63,28 @@ namespace Xamarin.Forms.Platform.iOS
return color.ToUIColor();
}
+#else
+ public static NSColor ToNSColor(this Color color)
+ {
+ return NSColor.FromRgba((float)color.R, (float)color.G, (float)color.B, (float)color.A);
+ }
+
+ public static NSColor ToNSColor(this Color color, Color defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor.ToNSColor();
+
+ return color.ToNSColor();
+ }
+
+ public static NSColor ToNSColor(this Color color, NSColor defaultColor)
+ {
+ if (color.IsDefault)
+ return defaultColor;
+
+ return color.ToNSColor();
+ }
+#endif
}
public static class PointExtensions
@@ -55,6 +93,11 @@ namespace Xamarin.Forms.Platform.iOS
{
return new Point(point.X, point.Y);
}
+
+ public static PointF ToPointF(this Point point)
+ {
+ return new PointF(point.X, point.Y);
+ }
}
public static class SizeExtensions