SwiftUI TextField: Border


TextField rounded border style is one of the styles available to format your control but if you don’t want to use rounded border then you can use border modifier to create a custom border around your TextField.
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()
    }
}

Notice we used padding right before the border modifier, that’s to provide some breathing room between TextField and border.