[macOS] Only use default font size for Time/DatePicker to avoid clipping issues ...
authorKonrad Müller <11095003+krdmllr@users.noreply.github.com>
Mon, 16 Sep 2019 21:06:49 +0000 (23:06 +0200)
committerGerald Versluis <gerald.versluis@microsoft.com>
Mon, 16 Sep 2019 21:06:49 +0000 (23:06 +0200)
* Only use default font size

* Always use default font size

* Remove duplicated code

* Remove extra spacing

Xamarin.Forms.Platform.MacOS/Renderers/DatePickerRenderer.cs
Xamarin.Forms.Platform.MacOS/Renderers/TimePickerRenderer.cs

index 5150ff1..e6ee6c3 100644 (file)
@@ -116,9 +116,17 @@ namespace Xamarin.Forms.Platform.MacOS
                void UpdateFont()
                {
                        if (Control == null || Element == null)
-                               return;
+                               return; 
+
+                       var newFont = Element.ToNSFont();
+
+                       // The font needs to have the default font size to avoid clipping
+                       var originalFontSize = (NSNumber)Control.Font.FontDescriptor.FontAttributes[NSFont.SizeAttribute];
+                       // Recreate the font with the default size
+                       newFont = NSFont.FromDescription(newFont.FontDescriptor, originalFontSize.FloatValue);
 
-                       Control.Font = Element.ToNSFont();
+                       // Apply the font 
+                       Control.Font = newFont;
                }
 
                void UpdateMaximumDate()
@@ -147,4 +155,4 @@ namespace Xamarin.Forms.Platform.MacOS
                                Control.TextColor = textColor.ToNSColor();
                }
        }
-}
\ No newline at end of file
+}
index 2350026..cddb3bd 100644 (file)
@@ -98,7 +98,15 @@ namespace Xamarin.Forms.Platform.MacOS
                        if (Control == null || Element == null)
                                return;
 
-                       Control.Font = Element.ToNSFont();
+                       var newFont = Element.ToNSFont();
+
+                       // The font needs to have the default font size to avoid clipping
+                       var originalFontSize = (NSNumber)Control.Font.FontDescriptor.FontAttributes[NSFont.SizeAttribute];
+                       // Recreate the font with the default size
+                       newFont = NSFont.FromDescription(newFont.FontDescriptor, originalFontSize.FloatValue);
+
+                       // Apply the font
+                       Control.Font = newFont;
                }
 
                void UpdateTime()
@@ -123,4 +131,4 @@ namespace Xamarin.Forms.Platform.MacOS
                                Control.TextColor = textColor.ToNSColor();
                }
        }
-}
\ No newline at end of file
+}