在iOS版本11.2中,我使用此代码设置了自动大写文本。运行正常。
*在Xamarin.Forms中:
公共静态只读BindableProperty HasAutoUpperCaseTextProperty
BindableProperty.Create( nameof(HasAutoUpperCaseText), typeof(bool), typeof(EditorExtend), false); public bool HasAutoUpperCaseText { get { return (bool)GetValue(HasAutoUpperCaseTextProperty); } set { SetValue(HasAutoUpperCaseTextProperty, value); } }
*在iOS渲染器中:
Control.AutocapitalizationType = UITextAutocapitalizationType.AllCharacters;
*问题:将iPAD的操作系统版本升级到iOS 11.4后,它无法正确运行。
您遇到过这个问题吗?如何在iOS 11.4中修复它?
答案 0 :(得分:1)
*在iOS渲染器中:
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var nativeTextField = (UITextField)Control;
nativeTextField.EditingChanged += (object sender, EventArgs args) =>
{
nativeTextField.Text = nativeTextField.Text.ToUpper();
};
}
}
答案 1 :(得分:0)
对于iOS平台:
[assembly: ExportEffect(typeof(EntryCapitalizeKeyboard), "EntryCapitalizeKeyboard")]
namespace YourProject.Platform.iOS.Renderers
{
[Preserve(AllMembers = true)]
public class EntryCapitalizeKeyboard : PlatformEffect
{
private UITextAutocapitalizationType _old;
protected override void OnAttached()
{
var editText = Control as UITextField;
if (editText == null)
return;
_old = editText.AutocapitalizationType;
editText.AutocapitalizationType = UITextAutocapitalizationType.AllCharacters;
}
protected override void OnDetached()
{
var editText = Control as UITextField;
if (editText == null)
return;
editText.AutocapitalizationType = _old;
}
}
}
答案 2 :(得分:0)
以防万一其他人遇到此问题,在XAML中向您的编辑器添加Keyboard =“ Chat”会自动执行此操作。我认为它也适用于所有平台。 您还可以根据需要尝试其他键盘选项。