How to edit FocusRing shape
Or how to disable it?
import SwiftUI
struct FilterFieldView : View{
@State var filterStr: String = ""
var body : some View{
ZStack{
TextField("Filter", text: $filterStr)
.textFieldStyle(PlainTextFieldStyle())
.padding(.vertical, 2)
.multilineTextAlignment(.center)
.background(Color.clear)
.padding(.trailing, 20)
// needed to set border color
// + set field border beyond the "x" button
.addBorder(color: Color.gray, radius: 10, lineWidth: 1)
HStack() {
Spacer()
Button("X"){ self.filterStr = "" }
.buttonStyle(PlainButtonStyle()) //remove default button style
.padding(3)
.background(
Circle()
.stroke(Color.gray, lineWidth: 1)
)
.padding(.horizontal, 3)
}
}
}
}
and addBorder extension (NOT NECESSARY CODE):
extension View {
func addBorder(color: Color, radius: Int, lineWidth: Int) -> some View
{
self.modifier( CustomBorder(color: color, radius: CGFloat(radius), lineWidth: CGFloat(lineWidth) ) )
}
}
struct CustomBorder: ViewModifier {
@State var color: Color
@State var radius: CGFloat
@State var lineWidth: CGFloat
func body (content: Content) -> some View
{
content
.overlay(
RoundedRectangle(cornerRadius: radius)
.stroke(color, lineWidth: lineWidth)
)
}
}