summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs35
1 files changed, 32 insertions, 3 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs b/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs
index dce86b98..825a20bd 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs
@@ -1,7 +1,13 @@
using Foundation;
+#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 FormattedStringExtensions
{
@@ -19,10 +25,16 @@ namespace Xamarin.Forms.Platform.iOS
if (fgcolor.IsDefault)
fgcolor = Color.Black; // as defined by apple docs
+#if __MOBILE__
return new NSAttributedString(span.Text, font == Font.Default ? null : font.ToUIFont(), fgcolor.ToUIColor(), span.BackgroundColor.ToUIColor());
+#else
+ return new NSAttributedString(span.Text, font == Font.Default ? null : font.ToNSFont(), fgcolor.ToNSColor(),
+ span.BackgroundColor.ToNSColor());
+#endif
}
- public static NSAttributedString ToAttributed(this FormattedString formattedString, Font defaultFont, Color defaultForegroundColor)
+ public static NSAttributedString ToAttributed(this FormattedString formattedString, Font defaultFont,
+ Color defaultForegroundColor)
{
if (formattedString == null)
return null;
@@ -43,6 +55,7 @@ namespace Xamarin.Forms.Platform.iOS
if (span == null)
return null;
+#if __MOBILE__
UIFont targetFont;
if (span.IsDefault())
targetFont = ((IFontElement)owner).ToUIFont();
@@ -56,9 +69,25 @@ namespace Xamarin.Forms.Platform.iOS
fgcolor = Color.Black; // as defined by apple docs
return new NSAttributedString(span.Text, targetFont, fgcolor.ToUIColor(), span.BackgroundColor.ToUIColor());
+#else
+ NSFont targetFont;
+ if (span.IsDefault())
+ targetFont = ((IFontElement)owner).ToNSFont();
+ else
+ targetFont = span.ToNSFont();
+
+ var fgcolor = span.ForegroundColor;
+ if (fgcolor.IsDefault)
+ fgcolor = defaultForegroundColor;
+ if (fgcolor.IsDefault)
+ fgcolor = Color.Black; // as defined by apple docs
+
+ return new NSAttributedString(span.Text, targetFont, fgcolor.ToNSColor(), span.BackgroundColor.ToNSColor());
+#endif
}
- internal static NSAttributedString ToAttributed(this FormattedString formattedString, Element owner, Color defaultForegroundColor)
+ internal static NSAttributedString ToAttributed(this FormattedString formattedString, Element owner,
+ Color defaultForegroundColor)
{
if (formattedString == null)
return null;