当前位置:网站首页>SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
2022-07-01 18:47:00 【知识大胖】
从 SwiftUI 4 开始,Toggle视图现在能够绑定到多个值。现在我们可以使用以下重载初始化程序为值集合创建切换:
init(isOn:label:)
- isOn: 是一个绑定集合,用于确定切换是打开、关闭还是混合。
- Label: 是一个描述切换目的的视图。
还有两个额外的重载初始化:
init(_:isOn:)
其中第一个参数是titleKey(用于描述切换目的的切换本地化标题的键),第二个参数是isOn(确定切换是打开、关闭还是混合的绑定集合)
init(_:isOn:)
上面的初始化器与前一个类似,只是它需要一个字符串而不是titleKeyinit 。title
多个绑定
如前所述,toggle 现在支持多值绑定,所以让我们看一个示例。我们将从表示 HomeSecurity 用例的数据结构开始。
struct HomeSecurity: Hashable, Identifiable {
var id = UUID()
var armed: Bool
var name: String
}
让我们为这个结构添加一个扩展并添加一些示例数据来使用:
extension HomeSecurity {
static var exampleData: [HomeSecurity] = [
.init(armed: false, name: "Garage Door"),
.init(armed: true, name: "Front Door"),
边栏推荐
- Ffmpeg common commands (2)
- 墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
- What is the essential difference between Bi development and report development?
- Oracle物理体系结构
- 新增订单如何防止重复提交
- windows环境 redis安装和启动(后台启动)
- 自定义插入页面标签以及实现类似通讯录的首字母搜索
- Shell advanced
- 一文读懂C语言中的结构体
- Opencv video quality diagnosis - VIDEO occlusion diagnosis
猜你喜欢
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
Axure does not display catalogs
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
Regular expression =regex=regular expression
开发那些事儿:EasyCVR集群设备管理页面功能展示优化
Optimization of video streaming with repeated requests in the case of unstable easygbs network
Object creation
1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包
今日群里分享的面试题
安装sharp报错
随机推荐
DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
list大集合等比分割成多个小list集合
2022/6/8-2022/6/12
wireshark报文分析tcp,ftp
Related concepts of cookies and sessions
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
利用win7漏洞进行系统登录密码破解
Proxy in ES6
Unreal Engine packaging project
Redo和Undo的区别
解决VSCode下载慢或下载失败的问题
[untitled]
torch. nn. functional. Interpolate function
Define dichotomy lookup
Anaconda installs the virtual environment to the specified path
[SQL optimization] the difference between with as and temporary tables
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
[exercise] HashSet
[AI server setup] CUDA environment
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?