当前位置:网站首页>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"),
边栏推荐
- AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
- Compile ffmpeg source code with msys+vs2019 under win10
- GC garbage collection
- 全国职业院校技能大赛网络安全“splunk“详细配置
- JS proxy
- mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
- HLS4ML进入方法
- Crunch简介、安装,使用Crunch制作密码字典
- Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
- P2433 【深基1-2】小学数学 N 合一
猜你喜欢

【多线程】锁策略

SQL 入门计划-1-选择

How to use console Log print text?

Bind this of the current scope for callback functions in other cases such as timers and delayers

Test self-study people must see: how to find test items in software testing?
![P2433 [deep foundation 1-2] primary school mathematics n in one](/img/28/e5eab8927694ea002b536202a1b5ea.png)
P2433 [deep foundation 1-2] primary school mathematics n in one

Review the collection container again

After studying 11 kinds of real-time chat software, I found that they all have these functions

Servlet knowledge points

对象的创建
随机推荐
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
JDBC中如何添加事务
Time series analysis using kibana timelion
【无标题】
Optaplanner learning notes (I) case cloud balance
一文读懂C语言中的结构体
对象的创建
Class loading mechanism
Uni app product classification
Opencv video quality diagnosis - VIDEO occlusion diagnosis
DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
[AI server setup] CUDA environment
Interview question 1
torch. nn. functional. Interpolate function
SIP protocol of gb28181
Cookie和Session的相关概念
Modsim basic use (Modbus simulator)
JS proxy
Actual combat of flutter - fast implementation of audio and video call application
PowerDesigner design name and comment replacement