swift - 单击另一个按钮时如何更改一个按钮的操作(SwiftUI)?
问题描述
在我的应用程序中,我有一个按钮,每次按下它都会输出一个特定的警报。但是,我想要它,以便当我单击该按钮 10 次时,按钮的操作和标签会发生变化,因为我想将其变成重新启动按钮。我该怎么做?
换句话说,我如何引用一个按钮并在它没有名称时修改它的属性?
'''迅速
Button(action: { alertIsVisible = true
}) {
Text(buttonText)
.fontWeight(.bold)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(20)
}
.alert(isPresented: $alertIsVisible, content: {
let roundedValue = Int(sliderValue.rounded())
let points = game.points(sliderValue: roundedValue)
return Alert(title: Text("Hello!"), message: Text("The slider's value is \(roundedValue).\n" + "You scored \(points) points this round"), dismissButton: .cancel(
{game.target = Int.random(in: 1...100)
roundTracker += 1
scoreTracker += points
}
))
})
'''
解决方案
推荐阅读
- python - 如何处理 BigQuery Stream Pipeline 中的非 ascii 字符?
- database - Cassandra 通过主键查询和列抛出错误
- python-3.x - 在 Flask API (windows) 中创建批处理文件以执行 POST 方法
- wpf - 如何在 ObjectDataProvider 中引用另一个类的枚举?
- database - 如何将关系数据模型转换为 NoSQL 文档存储类型数据模型?
- python - 无法将字符串转换为浮点数:'cafe'
- c# - 如何使用 Visual Studio 将 XAMPP MySQL 连接到 ADO.NET Entity Framework?
- c# - wsdl 和 xsd 都指向 Microsoft SOAP webservices 服务器上的 localhost 地址
- informatica - 如何使用 Informatica 将 varchar 加载到 SQL Server 中的日期类型中?
- debugging - 如何通过r2或r2pipe获取函数参数列表和返回值(类型和值),静态反汇编和动态调试?