using Xamarin.Forms;
namespace YourNamespace.Controls
{
public class ExtendedEntry : Entry { }
}
/*
Based on example from: https://forums.xamarin.com/discussion/18346/add-done-button-to-
keyboard-on-ios
*/
using System.Drawing;
using YourNamespace.Controls;
using YourNamespace.iOS.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedEntry), typeof(ExtendedEntryRenderer))]
namespace YourNamespace.iOS.Renderers
{
public class ExtendedEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Element == null)
return;
// Check only for Numeric keyboard
if (this.Element.Keyboard == Keyboard.Numeric)
this.AddDoneButton();
}
/// <summary>
/// <para>Add toolbar with Done button</para>
/// </summary>
protected void AddDoneButton()
{
var toolbar = new UIToolbar(new RectangleF(0.0f, 0.0f, 50.0f, 44.0f));
var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate
{
this.Control.ResignFirstResponder();
var baseEntry = this.Element.GetType();
((IEntryController)Element).SendCompleted();
});
toolbar.Items = new UIBarButtonItem[] {
new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace),
doneButton
};
this.Control.InputAccessoryView = toolbar;
}
}
}
1条答案
按热度按时间ecfdbz9o1#
在iOS的数字键盘上添加完成按钮没有标准的方法。在我的应用程序中,我通过在控制器导航项的右上角放置完成按钮来解决这个问题。
另一个选择是为numerical Entry创建自定义渲染器(在我们的例子中是ExtendedEntry自定义控件)。
注意:您必须更新.NET MAUI的命名空间和您的命名空间
字符串
Source