@Entry @Component struct RichEditorMaxLines { // 定义变量 private editorPadding: string = '8vp'; // 设置上下左右padding private fontSize: string = '16fp'; // 设置字体大小 private minLine: number = 1; // 设置最小行数 private maxLine: number = 3; // 设置最大行数 private lineHeight: string = '18fp'; // 设置单行高度 controller: RichEditorStyledStringController = new RichEditorStyledStringController(); build() { Column() { Row() { RichEditor({ controller: this.controller }) .padding(this.editorPadding) .onReady(() => { this.controller.setTypingStyle({ fontSize: this.fontSize, lineHeight: this.lineHeight }); }) // 计算最小和最大高度:minHeight/maxHeight=上下padding+行数minLine/maxLine*行高lineHeight .constraintSize({ minHeight: `${2 * parseFloat(this.editorPadding) + this.minLine * parseFloat(this.lineHeight)}vp`, maxHeight: `${2 * parseFloat(this.editorPadding) + this.maxLine * parseFloat(this.lineHeight)}vp` }); }.borderRadius('12vp') .width('90%') .backgroundColor('#F1F3F5'); } .width('100%') .height('100%') .justifyContent(FlexAlign.Center); } }
Q:RichEditor是否支持单行输入?
A:当前RichEditor不支持单行输入,若需要实现单行输入的能力,请使用组件TextInput。
Q:RichEditor组件,通过addTextSpan方法添加文本,文本行高最大能缩放到多少倍?
A:详细可查看RichEditorTextStyle的lineHeight字段的说明,设置值不大于0时,不限制文本行高,自适应字体大小。