繁体   English   中英

SwiftUI - 圆形文本字段

[英]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)

2022 年,SwiftUI 2.0

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM