added custom font renderers for ios dynamic text

This commit is contained in:
Kyle Spearrin 2016-06-28 08:21:39 -04:00
parent 818b1c426f
commit 734d2632dc
3 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using System;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Label), typeof(CustomLabelRenderer))]
namespace Bit.iOS.Controls
{
public class CustomLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var view = e.NewElement as Label;
if(Control != null && view != null)
{
var descriptor = UIFontDescriptor.PreferredBody;
var pointSize = descriptor.PointSize;
var size = view.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
{
pointSize *= 1.7f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label)))
{
pointSize *= .6f;
}
UIFont.FromDescriptor(descriptor, pointSize);
}
}
}
}

View File

@ -21,6 +21,8 @@ namespace Bit.iOS.Controls
var view = e.NewElement as ExtendedEntry; var view = e.NewElement as ExtendedEntry;
if(view != null) if(view != null)
{ {
UIFont.FromDescriptor(UIFontDescriptor.PreferredBody, 1.0f);
SetBorder(view); SetBorder(view);
SetMaxLength(view); SetMaxLength(view);
UpdateKeyboard(); UpdateKeyboard();

View File

@ -101,6 +101,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\ContentPageRenderer.cs" /> <Compile Include="Controls\ContentPageRenderer.cs" />
<Compile Include="Controls\CustomLabelRenderer.cs" />
<Compile Include="Controls\ExtendedSwitchCellRenderer.cs" /> <Compile Include="Controls\ExtendedSwitchCellRenderer.cs" />
<Compile Include="Controls\ListViewRenderer.cs" /> <Compile Include="Controls\ListViewRenderer.cs" />
<Compile Include="Controls\ExtendedViewCellRenderer.cs" /> <Compile Include="Controls\ExtendedViewCellRenderer.cs" />