1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-28 14:13:25 +00:00

Implemented funcitonality for extension pin VC. Apply size adjustments on proeprty changed for Labels.

This commit is contained in:
Kyle Spearrin
2016-07-20 20:57:00 -04:00
parent d0bf141c5d
commit 1fffeb5614
4 changed files with 157 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
@@ -16,25 +17,51 @@ namespace Bit.iOS.Controls
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.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
UpdateFont();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == Label.TextColorProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.FontProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.TextProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.FormattedTextProperty.PropertyName)
{
UpdateFont();
}
}
private void UpdateFont()
{
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
var size = Element.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize);
}
}
}