From 7fc2de3b1127accd6aa77eb6670d8ce54d56e51d Mon Sep 17 00:00:00 2001 From: DCloud_iOS_XHY Date: Thu, 1 Aug 2024 20:29:45 +0800 Subject: [PATCH] Update input.md --- docs/component/input.md | 44 ++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/docs/component/input.md b/docs/component/input.md index ce75df87..da50fc64 100644 --- a/docs/component/input.md +++ b/docs/component/input.md @@ -8,28 +8,44 @@ - - -#### 获取原生view对象 - -**Android 平台:** - -获取input组件对应的UniElement对象,通过UniElement对象的[getAndroidView](../dom/unielement.md#getandroidview-2)函数获取组件原生view对象 - -```uts -//导入安卓原生AppCompatEditText对象 -import AppCompatEditText from "androidx.appcompat.widget.AppCompatEditText" + + +#### 获取原生view对象 + +**Android 平台:** + +获取input组件对应的UniElement对象,通过UniElement对象的[getAndroidView](../dom/unielement.md#getandroidview-2)函数获取组件原生view对象 + +```uts +//导入安卓原生AppCompatEditText对象 +import AppCompatEditText from "androidx.appcompat.widget.AppCompatEditText" //通过input组件定义的id属性值,获取input标签的UniElement对象 const inputElement = uni.getElementById(id) //UniElement.getAndroidView设置泛型为安卓底层AppCompatEditText对象,直接获取AppCompatEditText, 如果泛型不匹配会返回null -if(inputElement != null) { +if(inputElement != null) { //editText就是input组件对应的原生view对象 const editText = inputElement.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 +//通过 input 组件定义的 id 属性值,获取 input 标签的 UniElement 对象 +const inputElement = uni.getElementById(id) +//获取原生 view +const view = inputElement?.getIOSView(); +//判断 view 是否存在,类型是否为 UITextField +if (view != null && view instanceof UITextField) { + //将 view 转换为 UITextField 类型 + const textField = view! as UITextField; +} +``` + +更多示例请参考 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