gpt4 book ai didi

ios - 在 SwiftUI、Xcode 11.2 中展开 TextField 上的可点击区域

转载 作者:行者123 更新时间:2023-12-01 15:16:19 26 4
gpt4 key购买 nike

无法弄清楚如何使可点击区域更大以在 swiftUI(iOS 13、Xcode 11.2)上打开键盘。我只能影响视觉外观,但不能影响用户可以点击的实际区域(可点击区域 == 无论占位符文本的 fontSize 是什么。)

在 swiftUI 中创建 TextField 时,可以使用 frame() 来增加占位符文本周围的大小,我也可以使用 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)

我希望当您单击框架内的任何位置时,键盘会打开/您可以在文本字段中输入。但是,我需要单击占位符 Text 的上部才能在 TextField 中输入

最佳答案

一些工作,但工作。

 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))
}
}

关于ios - 在 SwiftUI、Xcode 11.2 中展开 TextField 上的可点击区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com