Not able to customize entry with underline using Customentryhandler with .NET MAUI on iOS targeting .NET 8. the values with view.Width and view.Height are showing as -1 but if I hardcode the values, I'm able to see the underline. Please help me to get the width and height or any other way to resolve the issue.
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("MyEntry", (handler, view) => {
#if __IOS__
handler.PlatformView.BorderStyle = UITextBorderStyle.None;
var borderLayer = new CALayer();
borderLayer.MasksToBounds = true;
borderLayer.Frame = new CoreGraphics.CGRect(0, view.Height-1, view.Width, 1);
borderLayer.BorderColor = view.TextColor.ToCGColor();
borderLayer.BorderWidth = 1.0f;
handler.PlatformView.Layer.AddSublayer(borderLayer);
#endif
});
This is because the entry doesn't measure and layout now. So you can't get the size such as height and width of the view. So you can put the code into the page's
LayoutChildren
method. Such as:In the xaml:
And in the contentpage.cs:
But you need to add the code for every entry in your project.
I have tested your code. The underline is not a really underline. It the border (
borderLayer.BorderColor = view.TextColor.ToCGColor();
) you set. So if you set the border color asborderLayer.BorderColor = Colors.Transparent.ToCGColor();
and hardcode the size of the entry, the underline will disappear. Such as:In the xaml
And in the App class's constructor: