【发布时间】:2020-04-06 09:45:56
【问题描述】:
我正在尝试做的是更新按钮标签的操作或 onTapGesture 文本。但我不知道如何从后面更新按钮的标签。
我得到 'ContentView' 类型的值没有成员 'lable'。
Button(action: {}) {
Text("Enroute")
}.foregroundColor(.red)
.onTapGesture {
self.lable(Text(getCurrentTime()))
}
并且 'ContentView' 类型的值在这里也没有成员 'lable'。
Button(action: {
self.lable(Text(getCurrentTime()))
}) {
Text("Enroute")
}.foregroundColor(.red)
ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Button(action: {}) {
Text("Enroute")
}.foregroundColor(.red)
Button(action: {}) {
Text("On Scene")
}.foregroundColor(.yellow)
Button(action: {}) {
Text("Leave Scene")
}.foregroundColor(.green)
Button(action: {}) {
Text("At Hospital")
}.foregroundColor(.blue)
Button(action: {}) {
Text("In Service")
}.foregroundColor(.gray)
}
.navigationBarTitle("Times")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
func getCurrentTime() -> String {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "HH:mm:ss"
return dateFormatter.string(from: Date())
}
【问题讨论】:
标签: swiftui