gpt4 book ai didi

swift - 如何摆脱 SwiftUI TextFields 周围的蓝色选择边框?

转载 作者:行者123 更新时间:2023-11-30 10:27:54 27 4
gpt4 key购买 nike

我使用以下代码创建了两个文本字段:


VStack (spacing: geometry.size.width/48) {
TextField("World Name", text: self.$WorldName)
.font(.system(size: geometry.size.width/28))
.textFieldStyle(PlainTextFieldStyle())
.frame(width: geometry.size.width*0.75)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color.init(white: 0.28))
)
TextField("World Seed", text: self.$WorldSeed)
.font(.system(size: geometry.size.width/28))
.textFieldStyle(PlainTextFieldStyle())
.frame(width: geometry.size.width*0.75)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color.init(white: 0.28))
)
Button (action: {
withAnimation {
self.back.toggle()
}
// Is there a way to "deselect" any textfields here
}){
Text("Back")
}
}

为什么当我点击一个时,有一个蓝色边框不随动画淡出,如何去除?这个问题很具体,我已经提供了代码和必要的细节,我不明白为什么它应该太难回答。

总而言之,我需要知道:

  • 如何去掉这个蓝色选择边框

或者

  • 如何立即取消选择按钮操作中的文本字段,
  • 如果我应用填充或圆角,则使边框与文本字段正确对齐。

这张图中唯一的蓝色是我指的边框 The only blue in this picture is the border I am referring to

如此屏幕截图所示,文本字段是圆形的,但选择边框没有圆角以反射(reflect)条目的圆角矩形形状 As shown in this screenshot, the textfield is round, but the selection border does not get round corners to reflect the rounded rectangle shape of the entry

蓝色边框不适合内边距

The blue border does not fit the padding

我添加了这样的填充 .padding([.leading, .trailing], 6)

最佳答案

您可以通过扩展 NSTextField 来删除蓝色边框(即使使用 PlainTextFieldStyle 时也会出现在 macOS 上),如下所示:

extension NSTextField {
open override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}

请参阅 Apple 开发者论坛答案 here

关于swift - 如何摆脱 SwiftUI TextFields 周围的蓝色选择边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59754983/

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