swiftui - Is there a possibility to deactivate a button in SwiftUI?
问题描述
Is there a possibility to deactivate a button in SwiftUI? Can not find anything?
I want to do a download with Alamofire and then activate the button after successful download.
解决方案
您可以使用.disabled
修饰符。根据文档:
添加控制用户是否可以与此视图交互的条件。
import SwiftUI
struct ContentView: View {
@State private var buttonDisabled = true
var body: some View {
Button(action: {
//your action here
}) {
Text("CLICK ME!")
}
.disabled(buttonDisabled)
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
buttonDisabled
下载完成后,您可以将State var 设置为 false。
推荐阅读
- c++ - 在 C++ 中使用 return 进行锻炼
- php - 如何使用带有中间件的条件句来显示树形菜单 Laravel
- c# - 如何从对象中获取值(c#/xamarin)
- interrupt - MSP430:尝试使用按钮和 LED 闪烁来学习中断
- powershell - 难以模拟 Invoke-WebRequest 的 BasicHtmlWebResponseObject
- angular - 在 ng-select 中显示 '>' 和 '<' 符号
- c# - 在 ASP.Net Core Razor 页面中使用会话包装器
- javascript - 在 Javascript 号码上使用 bind() 时,console.log() 输出代表什么?
- angular - 可观察到的特殊结果:使用 Jasmine 弹珠进行测试
- wordpress - 在 Wordpress 的 s2Member 中更新 Paypal API 签名时是否有任何“陷阱”?