Adjusted button and entry to handle font upadte on property changes

This commit is contained in:
Kyle Spearrin 2016-07-21 00:03:22 -04:00
parent 98335c6acb
commit 596a74b394
2 changed files with 67 additions and 21 deletions

View file

@ -3,6 +3,7 @@ using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.ComponentModel;
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
namespace Bit.iOS.Controls
@ -16,25 +17,39 @@ namespace Bit.iOS.Controls
var view = e.NewElement as Button;
if(Control != null && view != null)
{
var descriptor = UIFontDescriptor.PreferredBody;
var pointSize = descriptor.PointSize;
var size = view.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Button)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Button)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Button)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
UpdateFont();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == Button.FontProperty.PropertyName)
{
UpdateFont();
}
}
private void UpdateFont()
{
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
var size = Element.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Button)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Button)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Button)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize);
}
}
}

View file

@ -21,12 +21,10 @@ namespace Bit.iOS.Controls
var view = e.NewElement as ExtendedEntry;
if(view != null)
{
var descriptor = UIFontDescriptor.PreferredBody;
Control.Font = UIFont.FromDescriptor( descriptor, descriptor.PointSize );
SetBorder(view);
SetMaxLength(view);
UpdateKeyboard();
UpdateFont();
if(view.AllowClear)
{
@ -92,6 +90,39 @@ namespace Bit.iOS.Controls
{
UpdateKeyboard();
}
else if(e.PropertyName == Entry.FontAttributesProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Entry.FontFamilyProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Entry.FontSizeProperty.PropertyName)
{
UpdateFont();
}
}
private void UpdateFont()
{
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
var size = Element.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(ExtendedEntry)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(ExtendedEntry)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(ExtendedEntry)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromName(Element.FontFamily, pointSize);
}
private void SetBorder(ExtendedEntry view)