I use Rectangle()
在 TextField (SwiftUI) 上添加底部边框
但我想用protocol TextFieldStyle
对于 TextField 样式的底线,如 RoundedBorderTextFieldStyle
如何在不使用矩形的情况下为 TextField 创建自定义样式?
https://developer.apple.com/documentation/swiftui/staticmember https://developer.apple.com/documentation/swiftui/staticmember
struct ContentView : View {
@State private var username = "Text Hellow"
var body: some View {
VStack() {
TextField($username)
.foregroundColor(Color.yellow)
Rectangle()
.frame(height: 1.0, alignment: .bottom)
.relativeWidth(1)
.foregroundColor(Color.red)
}
.padding()
}
func editChanged() {
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Divider
可用于分隔其他内容的视觉元素。
您可以设置color
and height
Divider()
.frame(height: 1)
.padding(.horizontal, 30)
.background(Color.red)
struct LoginField: View {
@State private var email: String = ""
@State private var password: String = ""
var body: some View {
VStack {
TextField("Email", text: $email)
.padding(.horizontal, 30).padding(.top, 20)
Divider()
.padding(.horizontal, 30)
TextField("Password", text: $password)
.padding(.horizontal, 30).padding(.top, 20)
Divider()
.padding(.horizontal, 30)
Spacer()
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)