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
相关产品推荐
相关产品推荐

