← back to the blog


TextField text center SwiftUI

Posted on December 16th, 2019 in Swift by George

 

How to center text inside TextField SwiftUI

 



struct ContentView: View {
    
    @State private var textState: String = "";

    var body: some View {
        ZStack {
            Image("bgimage") // this is background image
            VStack {
                TextField("TEXT", text: $textState)
                    .foregroundColor(Color.black)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .padding()
                    .multilineTextAlignment(.center) // Center text ***!!!***
                    .fixedSize()
            }
        }
    }
}

 

Thank you!