gpt4 book ai didi

xcode - SwiftUI 文本字段颜色

转载 作者:行者123 更新时间:2023-12-03 08:35:24 27 4
gpt4 key购买 nike

知道如何更改文本字段占位符的颜色(如附图所示)吗?

我找不到将文本“电子邮件”着色为白色的方法,它始终保持灰色。

我想让它和图片一样。

非常感谢您的帮助

SecureField(String("Password"), text: $pass).padding(.all).border(Color.white).cornerRadius(3.0).padding(.horizontal)



i want to copy this

最佳答案

下面是一些可能方法的演示。也可能值得考虑围绕 UITextField 进行表示,因为它的可配置性要高得多。

使用 Xcode 11.7/iOS 13.7 进行测试

demo

struct PlaceholderTextFieldStyle: TextFieldStyle {
let placeholder: String
@Binding var text: String

init(_ placeholder: String, text: Binding<String>) {
self.placeholder = placeholder
self._text = text
}

func _body(configuration: TextField<Self._Label>) -> some View {
ZStack {
if text.isEmpty {
Text(placeholder)
}
configuration
}.foregroundColor(.white)
}
}

struct DemoView: View {
@State private var pass = ""

var body: some View {
SecureField("", text: $pass)
.textFieldStyle(PlaceholderTextFieldStyle("Password", text: $pass))
.padding(.all).border(Color.white).cornerRadius(3.0).padding(.horizontal)
.padding()
.background(Color.blue)

}
}

关于xcode - SwiftUI 文本字段颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63975796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com