![](/img/trans.png)
[英]SwiftUI: How can I add a new component to the list? Idea: Click the "plus"-button, enter a "Text", store it and... it's been added to the List
[英]How to add UI component on button click in SwiftUI?
您可以根据Button
点击添加随机 UI:
struct ContentView: View {
@State var isAddUI: Bool = false
var body: some View {
VStack(spacing: 20) {
Text("Hello..").font(.largeTitle).fontWeight(.bold)
if isAddUI {
Text("Adding Text after button clicked")
.font(.largeTitle)
.fontWeight(.regular)
}
Button(action: {
self.isAddUI = true
}) { Text("Add Text") }
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.