如何解决如何在 xamarin 表单 ios 中删除视觉材料条目下划线 条目条目
我们正在为我们的项目使用视觉材料条目。
using Xamarin.Forms.Material.IOS;
[assembly: ExportRenderer(typeof(Entry),typeof(CustomMaterialEntryRenderer),new[] { typeof(VisualMarker.MaterialVisual) })]
namespace MyApp.Android
{
public class CustomMaterialEntryRenderer : MaterialProgressBarRenderer
{
//...
}
}
如何去除xamarin表单ios中的材料条目下划线?
解决方法
您可以将活动下划线高度设置为 0f
以实现此目的:
[assembly: ExportRenderer(typeof(CustomMaterialEntry),typeof(CustomMaterialEntryRenderer),new[] { typeof(VisualMarker.MaterialVisual) })]
namespace MyApp.iOS
public class CustomMaterialEntryRenderer : MaterialEntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (this.Control != null)
{
Control.ActiveTextInputController.UnderlineHeightActive = 0f;
}
}
}
,
您可以使用 custom renderers 和 material visual 来实现条目下划线的去除。 我正在使用以下代码将其应用于项目中的所有条目,并且它正在与 Xamarin Forms 4.8+ 一起使用
Xamarin 安卓
条目
[assembly: ExportRenderer(typeof(Entry),typeof(EntryMaterialRendererAndroid),new[] { typeof(VisualMarker.MaterialVisual) })]
namespace XFTest.Droid.Renderers
{
public class EntryMaterialRendererAndroid : MaterialEntryRenderer
{
public EntryMaterialRendererAndroid(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BoxStrokeWidth = 0;
Control.BoxStrokeWidthFocused = 0;
}
}
}
}
Xamarin iOS
条目
[assembly: ExportRenderer(typeof(Entry),typeof(EntryMaterialRendereriOS),new[] { typeof(VisualMarker.MaterialVisual) })]
namespace XFTest.iOS.Renderers
{
public class EntryMaterialRendereriOS : MaterialEntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
EntryRemoveUnderLine();
}
protected override void OnElementPropertyChanged(object sender,PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender,e);
EntryRemoveUnderLine();
}
protected void EntryRemoveUnderLine()
{
if (Control != null)
{
Control.BorderStyle = UITextBorderStyle.None;
Control.Underline.Enabled = false;
Control.Underline.DisabledColor = UIColor.Clear;
Control.Underline.Color = UIColor.Clear;
Control.Underline.BackgroundColor = UIColor.Clear;
Control.ActiveTextInputController.UnderlineHeightActive = 0f;
Control.PlaceholderLabel.BackgroundColor = UIColor.Clear;
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。