我不知道如何在swiftUI (iOS 13,Xcode11.2)上增大可点击区域以打开键盘。我只能影响视觉外观,而不能影响用户可以点击的实际区域(无论占位符文本的fontSize是什么,可点击区域== )。
在swiftUI中创建字体时,可以使用TextField ()来增大占位符文本周围的大小,我也可以使用fontsize来增大框内的字体,但是没有什么方法可以在不增大字体的情况下使可点击区域(打开键盘)变大。
//修改TextFields代码
struct SignInModifier: ViewModifier {
func body(content: Content) -> some View {
return content
.padding(.all).font(.system(size: 18)).border(Color.purple).foregroundColor(Color.purple).shadow(radius: 2).frame(width: 350, height: 50)
}
}//我调用修饰符的地方
TextField("email address", text: $email).modifier(SignInModifier()).disableAutocorrection(true).keyboardType(.emailAddress)我希望当您单击框架内的任意位置时,键盘打开/您能够在textField中键入内容。但是,我只需要单击占位符文本的上半部分,就可以在TextField中键入内容
发布于 2019-10-30 12:13:36
好的,所以我想出了一个变通办法,但不完全是一个解决方案;只需将TextField嵌入到一个按钮中,无论您在哪里单击,它都会立即打开
发布于 2021-02-15 00:25:13
稍微做点工作,但还是行得通。
struct ContentView: View {
@State var name = ""
@State var isFocused = false
var body: some View {
ZStack {
HStack{
Text(name)
.font(.system(size: 50 , weight: .black))
.foregroundColor(isFocused ? Color.clear : Color.black)
Spacer()
}
TextField(name, text: $name , onEditingChanged: { editingChanged in
isFocused = editingChanged
})
.font(.system(size: isFocused ? 50 : 100 , weight: .black))
.foregroundColor(isFocused ? Color.black : Color.clear)
.frame(width: 300, height: isFocused ? 50 : 100 , alignment: .center)
.padding(.leading, isFocused ? 25 : 0 )
.padding(.trailing, isFocused ? 25 : 0 )
.padding(.top,isFocused ? 25 : 0 )
.padding(.bottom,isFocused ? 25 : 0 )
}.frame(width: 300)
.background(Color.red.opacity(0.3))
}
}https://stackoverflow.com/questions/58618470
复制相似问题