我在 SwiftUI 中创建了一个文本字段和一个安全文本字段,但我不知道如何在 SwiftUI 中将图像添加到我的文本字段/安全文本字段中。与旧版本的 Swift 相比,SwiftUI 的在线文档并不多。我还想将(占位符/键入的文本)移动指定的量,例如向右移动 30 点。我还试图查看背景颜色是否会从白色变为红色,但正如您所见,它在我的代码中,对 UI 没有影响。
注意:我的代码中有前面调用的 GeometryReader 以及用户名和密码的 @state 变量。
VStack (spacing: deviceSize.size.height * (50/812)) {
TextField ("Username", text: self.$username)
.foregroundColor(.black)//text color when you type
.accentColor(.blue)//cursor color
.background(Color(.red))//????
.textFieldStyle(RoundedBorderTextFieldStyle())
.cornerRadius(50)
// .border(Color.white)
//.font(.title)
SecureField ("Password", text: self.$password)
.textFieldStyle(RoundedBorderTextFieldStyle())
.cornerRadius(50)
}
.padding(.init(top: 0, leading: deviceSize.size.width * (38/375), bottom: 0, trailing: deviceSize.size.width * (38/375)))