Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
8e478b6e
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5877
Star
86
Fork
160
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
16
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
16
Issue
16
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8e478b6e
编写于
7月 25, 2024
作者:
DCloud_iOS_XHY
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交iOS平台 native-button 示例
上级
abe2492b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
57 addition
and
5 deletion
+57
-5
pages/component/object/object.uvue
pages/component/object/object.uvue
+1
-1
uni_modules/uni-native-button/components/native-button/native-button.vue
...-native-button/components/native-button/native-button.vue
+6
-3
uni_modules/uni-native-button/utssdk/app-android/index.uts
uni_modules/uni-native-button/utssdk/app-android/index.uts
+1
-1
uni_modules/uni-native-button/utssdk/app-ios/config.json
uni_modules/uni-native-button/utssdk/app-ios/config.json
+3
-0
uni_modules/uni-native-button/utssdk/app-ios/index.uts
uni_modules/uni-native-button/utssdk/app-ios/index.uts
+46
-0
未找到文件。
pages/component/object/object.uvue
浏览文件 @
8e478b6e
<template>
<view>
<native-button class="native-button" style="width: 200px; height: 100px;" :text="buttonText" @
t
ap="ontap"
<native-button class="native-button" style="width: 200px; height: 100px;" :text="buttonText" @
buttonT
ap="ontap"
@load="onload"></native-button>
<time-picker class="native-time-picker" :hour=2 :minute=3 @changed="onChanged"></time-picker>
...
...
uni_modules/uni-native-button/components/native-button/native-button.vue
浏览文件 @
8e478b6e
<
template
>
<object
@
init=
"onObjectInit"
@
click=
"onclick"
></object>
<object
@
init=
"onObjectInit"
@
c
ustomC
lick=
"onclick"
></object>
</
template
>
...
...
@@ -39,11 +39,14 @@
this
.
$emit
(
"
load
"
)
},
onclick
(
e
:
UniObjectCustomEvent
)
{
this
.
$emit
(
"
t
ap
"
,
e
)
this
.
$emit
(
"
buttonT
ap
"
,
e
)
}
},
unmounted
()
{
// #ifdef APP-IOS
// iOS平台需要主动释放 uts 实例
this
.
button
.
destroy
()
// #endi
}
}
</
script
>
...
...
uni_modules/uni-native-button/utssdk/app-android/index.uts
浏览文件 @
8e478b6e
...
...
@@ -18,7 +18,7 @@ export class NativeButton {
this.button?.setOnClickListener(_ => {
const detail = {}
//构建自定义UniObjectCustomEvent返回对象
const event = new UniObjectCustomEvent("click", detail)
const event = new UniObjectCustomEvent("c
ustomC
lick", detail)
//响应分发原生Button的点击事件
$element.dispatchEvent(event)
})
...
...
uni_modules/uni-native-button/utssdk/app-ios/config.json
0 → 100644
浏览文件 @
8e478b6e
{
"deploymentTarget"
:
"12"
}
uni_modules/uni-native-button/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
8e478b6e
import { UIButton, UIControl,ButtonType } from "UIKit"
export class NativeButton {
element : UniObjectElement;
button : UIButton;
constructor(element : UniObjectElement) {
this.element = element;
this.button = new UIButton(type=UIButton.ButtonType.system)
super.init()
// 在 swift target-action 对应的方法需要以OC的方式来调用,那么OC语言中用Selector来表示一个方法的名称(又称方法选择器),创建一个Selector可以使用 Selector("functionName") 的方式。
const method = Selector("buttonClickAction")
// button 添加点击回调
button.addTarget(this, action = method, for = UIControl.Event.touchUpInside)
this.bind();
}
// element 绑定原生view
bind() {
this.element.bindIOSView(this.button);
}
// 更新button文字
updateText(text : string) {
this.button.setTitle(text, for = UIControl.State.normal)
}
/**
* 按钮点击回调方法
* 在 swift 中,所有target-action (例如按钮的点击事件,NotificationCenter 的通知事件等)对应的 action 函数前面都要使用 @objc 进行标记。
*/
@objc buttonClickAction() {
// 发送事件
let event = new UniObjectCustomEvent("customClick")
this.element.dispatchEvent(event)
}
destroy() {
UTSiOS.destroyInstance(self)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录