struct TextFieldExample: View { @State private var title: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Enter title here", text: $title) HStack { Text("New title: ") Text(title) .bold() } }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .textFieldStyle(.roundedBorder) .multilineTextAlignment(.center) TextField("Course category", text: $category) .textFieldStyle(.roundedBorder) .multilineTextAlignment(.trailing) TextField("Course type", text: $type) .textFieldStyle(.roundedBorder) .multilineTextAlignment(.leading) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .textFieldStyle(.roundedBorder) .textInputAutocapitalization(.words) TextField("Course category", text: $category) .textFieldStyle(.roundedBorder) .textInputAutocapitalization(.characters) TextField("Course type", text: $type) .textFieldStyle(.roundedBorder) .textInputAutocapitalization(.never) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .textFieldStyle(.roundedBorder) .font(.custom("Chalkduster", size: 16)) TextField("Course category", text: $category) .textFieldStyle(.roundedBorder) .font(.custom("Georgia", size: 16)) TextField("Course type", text: $type) .textFieldStyle(.roundedBorder) .font(.system(size: 14, weight: .heavy, design: .rounded)) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .textFieldStyle(.roundedBorder) .disableAutocorrection(true) TextField("Course category", text: $category) .textFieldStyle(.roundedBorder) TextField("Course type", text: $type) .textFieldStyle(.roundedBorder) .disableAutocorrection(true) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .padding(5) .border(Color.orange, width: 2) TextField("Course category", text: $category) .padding(5) .border(Color.teal, width: 2) TextField("Course type", text: $type) .padding(5) .border(Color.pink, width: 2) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .padding(5) .background(Color.orange) TextField("Course category", text: $category) .padding(5) .background(Color.teal) TextField("Course type", text: $type) .padding(5) .background(Color.pink.opacity(0.2)) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.orange) ) TextField("Course category", text: $category) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.teal) ) TextField("Course type", text: $type) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.pink) ) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) TextField("Course title", text: $title) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.orange) ) .foregroundColor(Color.green) TextField("Course category", text: $category) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.teal) ) .foregroundColor(Color.blue) TextField("Course type", text: $type) .padding(5) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.pink) ) .foregroundColor(Color.purple) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var title: String = "" @State private var category: String = "" @State private var type: String = "" var body: some View { VStack { Text("DevTechie Courses") .font(.largeTitle) VStack(alignment: .leading) { Text("Enter new course title") .font(.title3) ZStack(alignment: .leading) { if title.isEmpty { Text("Course title") .bold() .foregroundColor(Color.purple.opacity(0.4)) } TextField("", text: $title) } .padding(.horizontal, 10) .padding(.vertical, 4) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.purple, lineWidth: 1) ) ZStack(alignment: .leading) { if category.isEmpty { Text("Course category") .bold() .foregroundColor(Color.teal.opacity(0.4)) } TextField("", text: $category) } .padding(.horizontal, 10) .padding(.vertical, 4) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.teal, lineWidth: 1) ) ZStack(alignment: .leading) { if type.isEmpty { Text("Course type") .bold() .foregroundColor(Color.pink.opacity(0.4)) } TextField("", text: $type) } .padding(.horizontal, 10) .padding(.vertical, 4) .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.pink, lineWidth: 1) ) }.padding(.top, 20) }.padding() } }
struct TextFieldExample: View { @State private var username = "" @State private var password = "" @State private var email = "" @State private var phone = "" var body: some View { VStack { Image("dt") .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2)) // username HStack { Image(systemName: "person.circle") .foregroundColor(.gray).font(.headline) TextField("username", text: $username) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) //password HStack { Image(systemName: "lock.circle") .foregroundColor(.gray).font(.headline) TextField("password", text: $password) Image(systemName: "eye.slash") .foregroundColor(.gray).font(.headline) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // email HStack { Image(systemName: "envelope") .foregroundColor(.gray).font(.headline) TextField("email", text: $email) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // email HStack { Image(systemName: "phone") .foregroundColor(.gray).font(.headline) TextField("phone", text: $email) Button(action: {}) { Image(systemName: "number.circle") } .tint(.orange) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) HStack { Button(action: {}) { Label("Sign Up", systemImage: "pencil.and.outline") } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Cancel", systemImage: "pencil.slash") } .buttonStyle(.bordered) } } } }
struct TextFieldExample: View { @State private var phone = "" @State private var age = "" @State private var name = "" @State private var securePhrase = "" @State private var email = "" var body: some View { VStack { Image("dt") .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2)) // phone HStack { Image(systemName: "phone") .foregroundColor(.gray).font(.headline) TextField("Phone number", text: $phone) .keyboardType(.phonePad) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) //age HStack { Image(systemName: "person") .foregroundColor(.gray).font(.headline) TextField("Age", text: $age) .keyboardType(.numberPad) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // name HStack { Image(systemName: "pencil") .foregroundColor(.gray).font(.headline) TextField("Name", text: $name) .keyboardType(.alphabet) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // secure phrase HStack { Image(systemName: "lock.doc.fill") .foregroundColor(.gray).font(.headline) TextField("Secure Phrase", text: $securePhrase) .keyboardType(.asciiCapable) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // secure phrase HStack { Image(systemName: "envelope") .foregroundColor(.gray).font(.headline) TextField("Email", text: $email) .keyboardType(.emailAddress) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) HStack { Button(action: {}) { Label("Sign Up", systemImage: "pencil.and.outline") } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Cancel", systemImage: "pencil.slash") } .buttonStyle(.bordered) } } } }
struct TextFieldExample: View { @State private var username = "" @State private var password = "" var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))Spacer() //username HStack { Image(systemName: "person") .foregroundColor(.gray).font(.headline) TextField("Username", text: $username) .keyboardType(.emailAddress) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // password HStack { Image(systemName: "lock.doc.fill") .foregroundColor(.gray).font(.headline) TextField("Password", text: $password) .keyboardType(.asciiCapable) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) HStack { Button(action: {}) { Label("Login", systemImage: "pencil.and.outline") } .buttonStyle(.borderedProminent) Button(action: {}) { Label("Cancel", systemImage: "pencil.slash") } .buttonStyle(.bordered) } } } }
struct TextFieldExample: View { @State private var email = "" @State private var confirmEmail = "" var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))//username HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("Email", text: $email) .keyboardType(.emailAddress) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) // password HStack { Image(systemName: "person.crop.circle.badge.checkmark") .foregroundColor(.gray).font(.headline) TextField("Confirm email", text: $confirmEmail) .keyboardType(.emailAddress) .disabled(email.isEmpty) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray, lineWidth: 1)) .padding(.horizontal) } } }
struct TextFieldExample: View { @State private var email = "" @State private var confirmEmail = "" @State private var borderColor: Color = .gray var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))//username HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("Email", text: $email) .keyboardType(.emailAddress) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) // password HStack { Image(systemName: "person.crop.circle.badge.checkmark") .foregroundColor(.gray).font(.headline) TextField("Confirm email", text: $confirmEmail) .keyboardType(.emailAddress) .disabled(email.isEmpty) .onSubmit { validateEmail() } } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) } } private func validateEmail() { if email.localizedCaseInsensitiveCompare(confirmEmail) == .orderedSame { borderColor = .green } else { borderColor = .red } } }
struct TextFieldExample: View { @State private var email = "" @State private var confirmEmail = "" @State private var borderColor: Color = .gray var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("Email", text: $email) .keyboardType(.emailAddress) .submitLabel(.next) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) HStack { Image(systemName: "person.crop.circle.badge.checkmark") .foregroundColor(.gray).font(.headline) TextField("Confirm email", text: $confirmEmail) .keyboardType(.emailAddress) .disabled(email.isEmpty) .onSubmit { validateEmail() } .submitLabel(.done) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) } } private func validateEmail() { if email.localizedCaseInsensitiveCompare(confirmEmail) == .orderedSame { borderColor = .green } else { borderColor = .red } } }
struct TextFieldExample: View { @State private var email = "" @State private var confirmEmail = "" @State private var borderColor: Color = .gray @FocusState private var focusConfirm: Bool var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("Email", text: $email) .keyboardType(.emailAddress) .submitLabel(.next) .onSubmit { focusConfirm = true } } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) HStack { Image(systemName: "person.crop.circle.badge.checkmark") .foregroundColor(.gray).font(.headline) TextField("Confirm email", text: $confirmEmail) .keyboardType(.emailAddress) .disabled(email.isEmpty) .onSubmit { validateEmail() } .submitLabel(.done) .focused($focusConfirm) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(borderColor, lineWidth: 1)) .padding(.horizontal) } } private func validateEmail() { if email.localizedCaseInsensitiveCompare(confirmEmail) == .orderedSame { borderColor = .green } else { borderColor = .red } } }
struct TextFieldExample: View { @State private var firstName: String = "" @State private var age: String = "" @FocusState private var focusAge: Bool var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("First Name", text: $firstName) .keyboardType(.asciiCapable) .submitLabel(.next) .onSubmit { focusAge = true } .onChange(of: firstName) { newValue in firstName = String(newValue.prefix(10)) } } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(.gray, lineWidth: 1)) .padding(.horizontal) HStack { Image(systemName: "heart.circle") .foregroundColor(.gray).font(.headline) TextField("Enter age", text: $age) .keyboardType(.emailAddress) .submitLabel(.done) .focused($focusAge) .onChange(of: age) { newValue in let filtered = newValue.filter { $0.isNumber } if newValue != filtered { age = filtered } } } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(.gray, lineWidth: 1)) .padding(.horizontal) } } }
struct TextFieldExample: View { @State private var firstName: String = "" @State private var age: String = "" @State private var firstNameEditing = false @State private var ageEditing = false var body: some View { VStack { Image("dt") .resizable() .frame(width: 100, height: 100) .clipShape(Circle()) .shadow(color: Color.black, radius: 2, x: 1, y: 1) .overlay(Circle().stroke(Color.gray, lineWidth: 2))HStack { Image(systemName: "person.crop.circle.fill") .foregroundColor(.gray).font(.headline) TextField("First Name", text: $firstName, onEditingChanged: { isEditing in firstNameEditing = isEditing }) .keyboardType(.asciiCapable) .submitLabel(.next) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(firstNameEditing ? .green : .gray, lineWidth: 1)) .padding(.horizontal) HStack { Image(systemName: "heart.circle") .foregroundColor(.gray).font(.headline) TextField("Enter age", text: $age, onEditingChanged: { isEditing in ageEditing = isEditing }) .keyboardType(.numberPad) .submitLabel(.done) } .padding() .overlay(RoundedRectangle(cornerRadius: 8).stroke(ageEditing ? .green : .gray, lineWidth: 1)) .padding(.horizontal) } } }