textfield自定义下划线类型

**

swift textfield自定义下划线类型

**
TextField(“请输入内容”, text: $userName)
.textFieldStyle(UnderLineTextFieldStyle())
.keyboardType(.default)

public struct UnderLineTextFieldStyle : TextFieldStyle {
@available(iOS 13.0,)
public func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.font(.callout)
.padding(.bottom, 10)
.background(
UnderLine()
.stroke(Color.black, lineWidth: 1.0)
.frame(alignment: .bottom)
)
}
}

@available(iOS 13.0, *)
struct UnderLine: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()

    path.move(to: CGPoint(x: rect.minX, y: rect.maxY))
    path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
    return path
}

}

Guess you like

Origin blog.csdn.net/u012477117/article/details/120378572