[英]SwiftUI - rounded textField
我有一个文本字段:
TextField("Message...", text: $chatViewModel.composedMessage)
.frame(height: 30)
.padding(10)
.background(RoundedRectangle(cornerRadius: 20))
.foregroundColor(Color(red: 237/255, green: 237/255, blue: 237/255))
它使用正确的foregroundColor
创建圆角,但文本颜色也与foregroundColor 相同。
所以如果我改变这个:
.foregroundColor(Color(red: 237/255, green: 237/255, blue: 237/255))
至
.foregroundColor(Color.black)
它改变了文本字段的背景颜色,但也改变了文本颜色,所以我永远看不到我在文本字段中实际输入的内容。
为 RoundedRectangle 添加文件颜色。
.background(RoundedRectangle(cornerRadius: 20).fill(Color(red: 237/255, green: 237/255, blue: 237/255))) // Here!!
.foregroundColor(.black)
TextField("File Name", text: $fileName)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("Email", text: $email)
.textFieldStyle(.plain)
.frame(height: 40)
.clipShape(Capsule())
.padding()
.overlay(RoundedRectangle(cornerRadius:10.0).strokeBorder(Color.gray, style: StrokeStyle(lineWidth: 1.0)))
.padding()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.