blob: 52764b9c2d01f0b00478db3d51e49bc821054fcb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
using System.ComponentModel;
using System.Drawing;
using UIKit;
namespace Xamarin.Forms.Platform.iOS
{
public class FrameRenderer : VisualElementRenderer<Frame>
{
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
SetupLayer();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName ||
e.PropertyName == Xamarin.Forms.Frame.OutlineColorProperty.PropertyName ||
e.PropertyName == Xamarin.Forms.Frame.HasShadowProperty.PropertyName ||
e.PropertyName == Xamarin.Forms.Frame.CornerRadiusProperty.PropertyName)
SetupLayer();
}
void SetupLayer()
{
float cornerRadius = Element.CornerRadius;
if (cornerRadius == -1f)
cornerRadius = 5f; // default corner radius
Layer.CornerRadius = cornerRadius;
if (Element.BackgroundColor == Color.Default)
Layer.BackgroundColor = UIColor.White.CGColor;
else
Layer.BackgroundColor = Element.BackgroundColor.ToCGColor();
if (Element.HasShadow)
{
Layer.ShadowRadius = 5;
Layer.ShadowColor = UIColor.Black.CGColor;
Layer.ShadowOpacity = 0.8f;
Layer.ShadowOffset = new SizeF();
}
else
Layer.ShadowOpacity = 0;
if (Element.OutlineColor == Color.Default)
Layer.BorderColor = UIColor.Clear.CGColor;
else
{
Layer.BorderColor = Element.OutlineColor.ToCGColor();
Layer.BorderWidth = 1;
}
Layer.RasterizationScale = UIScreen.MainScreen.Scale;
Layer.ShouldRasterize = true;
}
}
}
|