# ohos-autofittextview **Repository Path**: hihopeorg/ohos-autofittextview ## Basic Information - **Project Name**: ohos-autofittextview - **Description**: 自适应边界的textview组件,可自动调整文本大小 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-11-18 - **Last Updated**: 2023-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # autofittextview ## 简介 > 自动调整文本大小以完全适合其边界的TextView。 ## 效果展示 ![sample.gif](sample.gif) ## 下载安装 ```shell npm install @ohos/autofittextview --save ``` OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony npm包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_npm_usage.md) 。 ## 使用说明 ### 初始化 ``` @State content: string= '' @State textSize: number= 20 @State maxLines: number= 2 @State width: string= '100%' @State model: AutofitTextView.Model= new AutofitTextView.Model() ``` ### 设置属性 ``` private aboutToAppear() { this.model.setWidth(this.width) this.model.setText(this.content) this.model.setMaxLines(2) this.model.setTextSize(10,TypedValue.COMPLEX_UNIT_PX) this.model.setMinTextSize(2) this.model.setMaxTextSize(40) } ``` ### 在build中使用 ``` build() { Column() { AutofitTextView({ model: this.model }); } .alignItems(HorizontalAlign.Start) .padding(10) .width('100%') .height('100%') } ``` ## 接口说明 `@State model: AutofitTextView.Model= new AutofitTextView.Model()` 1. 设置控件宽度 `model.setWidth('100%')` 2. 设置字体大小 `model.setTextSize(10,TypedValue.COMPLEX_UNIT_PX)` 3. 设置最大字体 `model.setMaxTextSize(40)` 4. 设置最小字体 `model.setMinTextSize(2)` 5. 设置最大显示行数 `model.setMaxLines(2)` 6. 设置文本内容 `model.setText('test')` ## 约束与限制 在下述版本验证通过: - DevEco Studio 版本:3.1 Beta1(3.1.0.200),OpenHarmony SDK:API9(3.2.10.6)。 ## 目录结构 ```` |---- ohos-autofittextview | |---- entry # 示例代码文件夹 | |---- Autofittextview # autofittextview库文件夹 |---- scr/main/ets/Autofittextview # 自定义的Text控件 |---- scr/main/ets/TypedValue # 字体大小单位枚举类 | |---- index.ets # 对外接口 | |---- README.md # 安装使用方法 ```` ## 贡献代码 使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/ohos-autofittextview/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-sig/ohos-autofittextview/pulls) 。 ## 开源协议 本项目基于 [Apache License 2.0](https://gitee.com/openharmony-sig/ohos-autofittextview/blob/master/LICENSE) ,请自由地享受和参与开源。