diff options
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs | 114 |
1 files changed, 6 insertions, 108 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs index 82ceda81..e4967c15 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs @@ -1,21 +1,12 @@ using System; using System.ComponentModel; +using UIKit; using RectangleF = CoreGraphics.CGRect; using SizeF = CoreGraphics.CGSize; -#if __MOBILE__ -using UIKit; -using NativeLabel = UIKit.UILabel; - namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using NativeLabel = AppKit.NSTextField; - -namespace Xamarin.Forms.Platform.MacOS -#endif { - public class LabelRenderer : ViewRenderer<Label, NativeLabel> + public class LabelRenderer : ViewRenderer<Label, UILabel> { SizeRequest _perfectSize; @@ -60,16 +51,9 @@ namespace Xamarin.Forms.Platform.MacOS return result; } -#if __MOBILE__ public override void LayoutSubviews() { base.LayoutSubviews(); -#else - public override void Layout() - { - base.Layout(); -#endif - if (Control == null) return; @@ -101,12 +85,7 @@ namespace Xamarin.Forms.Platform.MacOS { if (Control == null) { - SetNativeControl(new NativeLabel(RectangleF.Empty)); -#if !__MOBILE__ - Control.Editable = false; - Control.Bezeled = false; - Control.DrawsBackground = false; -#endif + SetNativeControl(new UILabel(RectangleF.Empty) { BackgroundColor = UIColor.Clear }); } UpdateText(); @@ -124,7 +103,7 @@ namespace Xamarin.Forms.Platform.MacOS if (e.PropertyName == Label.HorizontalTextAlignmentProperty.PropertyName) UpdateAlignment(); else if (e.PropertyName == Label.VerticalTextAlignmentProperty.PropertyName) - UpdateLayout(); + LayoutSubviews(); else if (e.PropertyName == Label.TextColorProperty.PropertyName) UpdateText(); else if (e.PropertyName == Label.FontProperty.PropertyName) @@ -137,52 +116,23 @@ namespace Xamarin.Forms.Platform.MacOS UpdateLineBreakMode(); } -#if __MOBILE__ - protected override void SetAccessibilityLabel() - { - // If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Text, - // exit this method so we don't set the AccessibilityLabel value and break the binding. - // This may pose a problem for users who want to explicitly set the AccessibilityLabel to null, but this - // will prevent us from inadvertently breaking UI Tests that are using Query.Marked to get the dynamic Text - // of the Label. - - var elemValue = (string)Element?.GetValue(Accessibility.NameProperty); - if (string.IsNullOrWhiteSpace(elemValue) && Control?.AccessibilityLabel == Control?.Text) - return; - - base.SetAccessibilityLabel(); - } -#endif - protected override void SetBackgroundColor(Color color) { -#if __MOBILE__ if (color == Color.Default) BackgroundColor = UIColor.Clear; else BackgroundColor = color.ToUIColor(); -#else - if (color == Color.Default) - Layer.BackgroundColor = NSColor.Clear.CGColor; - else - Layer.BackgroundColor = color.ToCGColor(); -#endif - } void UpdateAlignment() { -#if __MOBILE__ Control.TextAlignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(); -#else - Control.Alignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(); -#endif } void UpdateLineBreakMode() { _perfectSizeValid = false; -#if __MOBILE__ + switch (Element.LineBreakMode) { case LineBreakMode.NoWrap: @@ -210,35 +160,6 @@ namespace Xamarin.Forms.Platform.MacOS Control.Lines = 1; break; } -#else - switch (Element.LineBreakMode) - { - case LineBreakMode.NoWrap: - Control.LineBreakMode = NSLineBreakMode.Clipping; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.WordWrap: - Control.LineBreakMode = NSLineBreakMode.ByWordWrapping; - Control.MaximumNumberOfLines = 0; - break; - case LineBreakMode.CharacterWrap: - Control.LineBreakMode = NSLineBreakMode.CharWrapping; - Control.MaximumNumberOfLines = 0; - break; - case LineBreakMode.HeadTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingHead; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.MiddleTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingMiddle; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.TailTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingTail; - Control.MaximumNumberOfLines = 1; - break; - } -#endif } void UpdateText() @@ -246,12 +167,9 @@ namespace Xamarin.Forms.Platform.MacOS _perfectSizeValid = false; var values = Element.GetValues(Label.FormattedTextProperty, Label.TextProperty, Label.TextColorProperty); - var formatted = values[0] as FormattedString; + var formatted = (FormattedString)values[0]; if (formatted != null) - { -#if __MOBILE__ Control.AttributedText = formatted.ToAttributed(Element, (Color)values[2]); - } else { Control.Text = (string)values[1]; @@ -259,28 +177,8 @@ namespace Xamarin.Forms.Platform.MacOS Control.Font = Element.ToUIFont(); Control.TextColor = ((Color)values[2]).ToUIColor(ColorExtensions.Black); } -#else - Control.AttributedStringValue = formatted.ToAttributed(Element, (Color)values[2]); - } - else - { - Control.StringValue = (string)values[1] ?? ""; - // default value of color documented to be black in iOS docs - Control.Font = Element.ToNSFont(); - Control.TextColor = ((Color)values[2]).ToNSColor(ColorExtensions.Black); - } -#endif - UpdateLayout(); - } - - void UpdateLayout() - { -#if __MOBILE__ LayoutSubviews(); -#else - Layout(); -#endif } } }
\ No newline at end of file |