在使用textInputAutocapitalization
时,我在应用格式时遇到问题.
当我们取消textInputAutocapitalization
的注释时,它在iOS 17上工作正常,但对于iOS 16,当用户输入超过9个字母并提交时,什么都不会发生.你知道哪里可以发行吗?
这是我的代码
import SwiftUI
struct ContentView: View {
@FocusState var isFocused: Bool
let lengh = 9
@State var text = ""
var body: some View {
VStack {
HStack {
TextField("write text here...",
value: $text,
format: .defaultUppercased)
.focused($isFocused)
//.textInputAutocapitalization(.characters)
}
.border(.black)
}
.padding()
.onChange(of: text) {
if text.count > lengh {
text = String($0.prefix(lengh))
}
}
}
}
#Preview {
ContentView()
}
public struct DefaultUppercasedFormatStyle: ParseableFormatStyle {
public init() {}
}
extension DefaultUppercasedFormatStyle {
public var parseStrategy: Self {
self
}
public func format(_ value: String) -> String {
value
}
}
extension DefaultUppercasedFormatStyle: ParseStrategy {
public func parse(_ value: String) -> String {
value.uppercased()
}
}
extension FormatStyle where Self == DefaultUppercasedFormatStyle {
public static var defaultUppercased: Self {
Self()
}
}