You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI无边框编辑器:iOS端UITextView无BorderStyle定义报错

解决MAUI中iOS端Editor移除下划线报错问题

你遇到的报错是因为iOS的UITextView控件根本没有BorderStyle属性——这个属性是UITextField专属的,你把两个控件的API搞混了,所以iOS端编译报错,Android端不受影响。

修改你的iOS平台代码即可解决问题,正确的代码如下:

public class BorderlessEditor : Editor
{
    public static void Setup()
    {
        Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping("BorderlessEditor", (handler, view) =>
        {
            if (view is BorderlessEditor)
            {
#if __ANDROID__
                    handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
#elif __IOS__
                    if (handler.NativeView is UIKit.UITextView textView)
                    {
                        textView.BackgroundColor = UIKit.UIColor.Clear;
                        // UITextView通过Layer控制边框,设置BorderWidth为0移除边框
                        textView.Layer.BorderWidth = 0;
                    }
#endif
            }
        });
    }
}

如果你的需求是移除输入文本的下划线(而非控件边框),可以在iOS代码块中额外添加:

  • textView.TextContainerInset = UIKit.UIEdgeInsets.Zero;
  • textView.TextContainer.LineBreakMode = UIKit.UILineBreakMode.Clip;

内容的提问来源于stack exchange,提问作者developer9969

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 09:52:11