swiftPunk
swiftPunk

Reputation: 1

How can I make my TextField starts from Top-leading in SwiftUI?

I have a simple code of TextField, which has a frame and background, the Text starts from Center-leading which I want it start from Top-leading, how can I do this? thanks

import SwiftUI

struct ContentView: View {
    
    @State private var stringOfText: String = "Hello, world!"
    
    var body: some View {

        TextField("", text: $stringOfText)
            .frame(width: 300, height: 200, alignment: .center)
            .background(Color.yellow)

    }
}

enter image description here

Upvotes: 3

Views: 2570

Answers (1)

dit_is_MJ
dit_is_MJ

Reputation: 116

You can try:

.frame(width: 300, height: 200, alignment: .top)

Upvotes: 10

Related Questions