import SwiftUI
import Combine
let maxCharacterLength: Int = 6
struct ContentView: View {
@State private var text: String = ""
var body: some View {
TextField("", text: $text)
.background(Color.orange)
.onReceive(Just(text)) { _ in
if(text.count > maxCharacterLength) {
text = String(text.prefix(maxCharacterLength))
}
}
}
}
网友评论