ui adjustment

This commit is contained in:
2020-05-05 12:13:50 +08:00
parent 0ce7757ec4
commit fdf4c128af
18 changed files with 583 additions and 84 deletions

View File

@ -0,0 +1,53 @@
using CoreGraphics;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CardView), typeof(CardViewRenderer))]
namespace Pixiview.iOS.Renderers
{
public class CardViewRenderer : VisualElementRenderer<CardView>
{
protected override void OnElementChanged(ElementChangedEventArgs<CardView> e)
{
base.OnElementChanged(e);
var layer = Layer;
var element = e.NewElement;
if (layer != null && element != null)
{
var cornerRadius = element.CornerRadius;
if (cornerRadius > 0)
{
layer.CornerRadius = cornerRadius;
}
//if (element.BackgroundColor != default)
//{
// layer.BackgroundColor = element.BackgroundColor.ToCGColor();
//}
var shadowColor = element.ShadowColor;
if (shadowColor != default)
{
layer.ShadowColor = shadowColor.ToCGColor();
layer.ShadowOpacity = 1f;
var radius = element.ShadowRadius;
if (radius > 0)
{
layer.ShadowRadius = radius;
}
layer.ShadowOffset = element.ShadowOffset.ToSizeF();
}
else
{
layer.ShadowOpacity = 0f;
}
}
}
}
}

View File

@ -12,9 +12,10 @@ namespace Pixiview.iOS.Renderers
{
base.OnElementChanged(e);
if (Control != null)
var layer = Layer;
if (layer != null)
{
Control.Layer.MasksToBounds = true;
layer.MasksToBounds = true;
}
}
@ -22,9 +23,10 @@ namespace Pixiview.iOS.Renderers
{
base.LayoutSubviews();
if (Control != null)
var control = Control;
if (control != null)
{
Control.Layer.CornerRadius = Control.Frame.Size.Width / 2;
control.Layer.CornerRadius = control.Frame.Size.Width / 2;
}
}
}

View File

@ -0,0 +1,56 @@
using CoreAnimation;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(RoundImage), typeof(RoundImageRenderer))]
namespace Pixiview.iOS.Renderers
{
public class RoundImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
var layer = Layer;
if (layer != null && e.NewElement is RoundImage image)
{
bool flag = false;
if (image.CornerRadius > 0)
{
layer.CornerRadius = image.CornerRadius;
flag = true;
}
var mask = image.CornerMasks;
if (mask != CornerMask.None)
{
var m = default(CACornerMask);
if ((mask & CornerMask.LeftTop) == CornerMask.LeftTop)
{
m |= CACornerMask.MinXMinYCorner;
}
if ((mask & CornerMask.RightTop) == CornerMask.RightTop)
{
m |= CACornerMask.MaxXMinYCorner;
}
if ((mask & CornerMask.LeftBottom) == CornerMask.LeftBottom)
{
m |= CACornerMask.MinXMaxYCorner;
}
if ((mask & CornerMask.RightBottom) == CornerMask.RightBottom)
{
m |= CACornerMask.MaxXMaxYCorner;
}
layer.MaskedCorners = m;
flag = true;
}
if (flag)
{
layer.MasksToBounds = true;
}
}
}
}
}

View File

@ -13,14 +13,22 @@ namespace Pixiview.iOS.Renderers
{
base.OnElementChanged(e);
if (Control != null && Element is RoundLabel label)
var layer = Layer;
if (layer != null && e.NewElement is RoundLabel label)
{
int radius = label.CornerRadius;
var radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
layer.CornerRadius = radius;
//layer.MasksToBounds = true;
}
else
{
layer.CornerRadius = 0;
}
if (layer.BackgroundColor != default)
{
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
}
}
}
@ -31,14 +39,15 @@ namespace Pixiview.iOS.Renderers
if (e.PropertyName == RoundLabel.CornerRadiusProperty.PropertyName)
{
if (Control != null && Element is RoundLabel label)
var layer = Layer;
if (layer != null && Element is RoundLabel label)
{
int radius = label.CornerRadius;
var radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
layer.CornerRadius = radius;
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
//layer.MasksToBounds = true;
}
}
}