Ниже представлено представление:
Код: Выделить всё
struct AutoView: View {
@State private var showGraduationDetails = false
let graduationTypes = ["Under Graduation", "Post Graduation", "Ph.D"]
@State private var graduationType = "" // New state variable to store graduation type
@State private var specialisation = "" // New state variable to store graduation type
@State private var graduationUniversity = "" // New state variable to store graduation type
@State private var cityOfUniversity = "" // New state variable to store graduation type
var body: some View {
ZStack { // Use ZStack to layer content on top of the background
LinearGradient(gradient: Gradient(colors: [.mint, .gray]), startPoint: .topLeading, endPoint: .bottomTrailing)
.ignoresSafeArea() // Extend gradient to entire screen
ScrollView {
VStack(spacing: 20) { // Add spacing between elements
VStack {
// Graduation details (conditionally displayed)
if showGraduationDetails {
VStack(alignment: .leading) {
ZStack { // Create a ZStack for the section
RoundedRectangle(cornerRadius: 20) // Rounded rectangle with translucent border
.fill(Color.white.opacity(0.1)) // Adjust opacity for translucency
.frame(width: 365) // Allow horizontal expansion
.frame(height: 50 /* Adjust height based on content */)
Picker("Graduation Type", selection: $graduationType) { // Use Picker for dropdown
Text("Select Graduation Type").tag("Select Graduation Type")
ForEach(graduationTypes, id: \.self) { type in
Text(type)
}
}
.pickerStyle(.menu)
}
// Specialisation
TextField("Degree Specialisation", text: $specialisation)
.foregroundColor(.white)
.padding()
.background(Color.white.opacity(0.2))
.cornerRadius(20)
// University of graduation
TextField("University of graduation", text: $graduationUniversity)
.foregroundColor(.white)
.padding()
.background(Color.white.opacity(0.2))
.cornerRadius(20)
// City of University
TextField("City of University", text: $cityOfUniversity)
.foregroundColor(.white)
.padding()
.background(Color.white.opacity(0.2))
.cornerRadius(20)
}
}
}
Button(action: {
showGraduationDetails.toggle() // Toggle visibility on click
}) {
Text(showGraduationDetails ? "Add more degree(s)" : "Add your degree(s)")
.fontWeight(.bold)
.foregroundColor(.yellow)
}
.frame(width: 170, height: 20, alignment: .center)
.padding()
.background(Color(UIColor.systemBlue).opacity(0.9))
.cornerRadius(20)
}
.padding() // Add padding around content
}
}
}
}

Нажав кнопку, я увидел текстовые поля, сгенерированные, как показано ниже.

Может ли кто-нибудь сообщить мне, есть ли способ создать тот же набор полей для добавления другого типа образования, нажав на ту же кнопку, по сути добавив n- количество подробностей об образовании.
Любая помощь приветствуется.
Подробнее здесь: https://stackoverflow.com/questions/786 ... clicking-a