我需要使用带有边框的圆形图像,我已经尝试使用ImageCircle插件,并且在当前版本的Xamarin中它已损坏,边框在iOS版本的图像外部出现,在android版本中有效。我也尝试创建一个自定义渲染器,但无法使其正常工作,它遵循我在google中搜索到的自定义渲染器的结果打印出来:
代码:
private void CreateCircle()
{
try
{
double min = Math.Min(Element.Width, Element.Height);
Control.Layer.CornerRadius = (float)(min / 2.0);
Control.Layer.MasksToBounds = false;
Control.Layer.BorderColor = Color.Red.ToCGColor();
Control.Layer.BorderWidth = 2;
Control.ClipsToBounds = true;
}
catch (Exception ex)
{
Debug.WriteLine("Unable to create circle image: " + ex);
}
}
仅当您设置HeightRequest
答案 0 :(得分:1)
根据Robin的评论,我相信您应该尝试使用FFImageLoading库。使用CircularTransformation
。您的XAML代码可能如下所示:
<ffimage:CachedImage Source="your_image.png"
HeightRequest="40"
WidthRequest="40">
<ffimage:CachedImage.Transformations>
<fftransformations:CircleTransformation BorderSize="2" BorderHexColor="#FF0000" />
</ffimage:CachedImage.Transformations>
</ffimage:CachedImage>
我相信,除了FFImageLoading nuget外,您还需要安装FFImageLoading.Transformation
编辑:看看官方的FFImageLoading CircularTransformation
sample code
答案 1 :(得分:1)
您需要确保Image
始终为正方形共享,然后渲染器将正确渲染它。由于HeightRequest
和WidthRequest
只是请求,因此可能会有些复杂,在某些布局中,最终可能并没有像他们建议的那样,但由于总有解决方案,因此请对布局进行更多搜索。 / p>