57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System.ComponentModel;
|
|
using Gallery.iOS.Renderers;
|
|
using Gallery.Resources.UI;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Platform.iOS;
|
|
|
|
[assembly: ExportRenderer(typeof(RoundLabel), typeof(RoundLabelRenderer))]
|
|
namespace Gallery.iOS.Renderers
|
|
{
|
|
public class RoundLabelRenderer : LabelRenderer
|
|
{
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
|
|
{
|
|
base.OnElementChanged(e);
|
|
|
|
var layer = Layer;
|
|
if (layer != null && e.NewElement is RoundLabel label)
|
|
{
|
|
var radius = label.CornerRadius;
|
|
if (radius > 0)
|
|
{
|
|
layer.CornerRadius = radius;
|
|
//layer.MasksToBounds = true;
|
|
}
|
|
else
|
|
{
|
|
layer.CornerRadius = 0;
|
|
}
|
|
if (layer.BackgroundColor != default)
|
|
{
|
|
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
if (e.PropertyName == RoundLabel.CornerRadiusProperty.PropertyName)
|
|
{
|
|
var layer = Layer;
|
|
if (layer != null && Element is RoundLabel label)
|
|
{
|
|
var radius = label.CornerRadius;
|
|
if (radius > 0)
|
|
{
|
|
layer.CornerRadius = radius;
|
|
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
|
|
//layer.MasksToBounds = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|