2016-06-29 06:44:47 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Bit.iOS.Controls;
|
|
|
|
|
using UIKit;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.Platform.iOS;
|
2016-07-21 07:03:22 +03:00
|
|
|
|
using System.ComponentModel;
|
2016-06-29 06:44:47 +03:00
|
|
|
|
|
|
|
|
|
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
|
|
|
|
|
namespace Bit.iOS.Controls
|
|
|
|
|
{
|
|
|
|
|
public class CustomButtonRenderer : ButtonRenderer
|
|
|
|
|
{
|
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementChanged(e);
|
|
|
|
|
|
|
|
|
|
var view = e.NewElement as Button;
|
|
|
|
|
if(Control != null && view != null)
|
|
|
|
|
{
|
2016-07-21 07:03:22 +03:00
|
|
|
|
UpdateFont();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-29 06:44:47 +03:00
|
|
|
|
|
2016-07-21 07:03:22 +03:00
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
2016-06-29 06:44:47 +03:00
|
|
|
|
|
2016-07-21 07:03:22 +03:00
|
|
|
|
if(e.PropertyName == Button.FontProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
UpdateFont();
|
2016-06-29 06:44:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-21 07:03:22 +03:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2016-07-26 01:00:57 +03:00
|
|
|
|
else if(size != Device.GetNamedSize(NamedSize.Default, typeof(Label)))
|
|
|
|
|
{
|
|
|
|
|
// not using dynamic font sizes, return
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-21 07:03:22 +03:00
|
|
|
|
|
|
|
|
|
Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize);
|
|
|
|
|
}
|
2016-06-29 06:44:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|