From 9d068bb8815e6122290bda34f06f566ca44ea284 Mon Sep 17 00:00:00 2001 From: DCloud_iOS_XHY Date: Thu, 1 Aug 2024 20:31:37 +0800 Subject: [PATCH] Update textarea.md --- docs/component/textarea.md | 44 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/docs/component/textarea.md b/docs/component/textarea.md index 4efaa020..03807899 100644 --- a/docs/component/textarea.md +++ b/docs/component/textarea.md @@ -8,28 +8,44 @@ - - -#### 获取原生view对象 - -**Android 平台:** - -获取textarea组件对应的UniElement对象,通过UniElement对象的[getAndroidView](../dom/unielement.md#getandroidview-2)函数获取组件原生view对象 - -```uts -//导入安卓原生AppCompatEditText对象 -import AppCompatEditText from "androidx.appcompat.widget.AppCompatEditText" + + +#### 获取原生view对象 + +**Android 平台:** + +获取textarea组件对应的UniElement对象,通过UniElement对象的[getAndroidView](../dom/unielement.md#getandroidview-2)函数获取组件原生view对象 + +```uts +//导入安卓原生AppCompatEditText对象 +import AppCompatEditText from "androidx.appcompat.widget.AppCompatEditText" //通过textarea组件定义的id属性值,获取textarea标签的UniElement对象 const textareaElement = uni.getElementById(id) //UniElement.getAndroidView设置泛型为安卓底层AppCompatEditText对象,直接获取AppCompatEditText, 如果泛型不匹配会返回null -if(textareaElement != null) { +if(textareaElement != null) { //editText就是textarea组件对应的原生view对象 const editText = textareaElement.getAndroidView() } ``` - -更多示例请参考 uts 插件 [uts-get-native-view](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts) + +**iOS 平台:** + +获取view组件对应的UniElement对象,通过UniElement对象的[getIOSView](../dom/unielement.html#getiosview)函数获取组件原生view对象 + +```uts +//通过 textarea 组件定义的 id 属性值,获取 textarea 标签的 UniElement 对象 +const textareaElement = uni.getElementById(id) +//获取原生 view +const view = inputElement?.getIOSView(); +//判断 view 是否存在,类型是否为 UITextView +if (view != null && view instanceof UITextView) { + //将 view 转换为 UITextView 类型 + const textField = view! as UITextView; +} +``` + +更多示例请参考 uts 插件 [uts-get-native-view](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/uni_modules/uts-get-native-view/utssdk/app-ios/index.uts) -- GitLab