当前位置:网站首页>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"),
边栏推荐
- [untitled]
- 简单但现代的服务器仪表板Dashdot
- 新窗口打开页面-window.open
- Anaconda installs the virtual environment to the specified path
- Bind this of the current scope for callback functions in other cases such as timers and delayers
- Interview questions for audio and video positions in Dachang -- today's headline
- 今日群里分享的面试题
- mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
- 解决VSCode下载慢或下载失败的问题
- Source code series of authentic children -inheritablethreadlocal (line by line source code takes you to analyze the author's ideas)
猜你喜欢
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]
![Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding](/img/56/0c7f39406814b5bf92eca5f6670e10.jpg)
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding

Class loading mechanism

How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results

AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
![[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached

JS 之 常用内置类的使用

SIP protocol of gb28181
随机推荐
Live HLS protocol
tensorflow报错Could not load dynamic library ‘libcudnn.so.8
一文读懂C语言中的结构体
Interview questions shared in today's group
Oracle物理体系结构
Brpc understanding
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
list分割成满足和不满足条件的集合(partitioningBy)
Example explanation: move graph explorer to jupyterlab
How to add transactions in JDBC
简单但现代的服务器仪表板Dashdot
Cookie和Session的相关概念
Shell advanced
振弦采集模塊測量振弦傳感器的流程步驟
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Collect Tiktok video
Install redis under Linux and configure the environment
DTD modeling
JDBC中如何添加事务
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached