当前位置:网站首页>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"),
边栏推荐
- Salesmartly has some tricks for Facebook chat!
- DDR4 test-2
- EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
- Compile ffmpeg source code with msys+vs2019 under win10
- Anaconda安装虚拟环境到指定路径
- Optimization of video streaming with repeated requests in the case of unstable easygbs network
- 一个悄然崛起的国产软件,低调又强大!
- Cookie和Session的相关概念
- 今日群里分享的面试题
- Axure does not display catalogs
猜你喜欢
Optimization of video streaming with repeated requests in the case of unstable easygbs network
Actual combat of flutter - fast implementation of audio and video call application
一个悄然崛起的国产软件,低调又强大!
【AI服务器搭建】CUDA环境
Salesmartly has some tricks for Facebook chat!
类加载机制
Axure does not display catalogs
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
Related concepts of cookies and sessions
Uni app wechat applet one click login to obtain permission function
随机推荐
Interview questions for audio and video positions in Dachang -- today's headline
实例讲解将Graph Explorer搬上JupyterLab
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
P2433 [deep foundation 1-2] primary school mathematics n in one
DDR4 test-2
Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
Ffmpeg common commands (2)
新增订单如何防止重复提交
开发那些事儿:EasyCVR集群设备管理页面功能展示优化
Brpc understanding
Interview question 1
703. The k-th element in the data flow
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
wireshark报文分析tcp,ftp
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
事务隔离级别 gap锁 死锁
【sql优化】with as 和 临时表的区别
Wireshark packet analysis TCP, FTP
通过js实现金字塔(星号金字塔,回文对称数字金字塔)
Analysis of GetMessage underlying mechanism