adjust UI
This commit is contained in:
56
Gallery.iOS/Renderers/RoundLabelRenderer.cs
Normal file
56
Gallery.iOS/Renderers/RoundLabelRenderer.cs
Normal file
@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user