在Xcode 11.2中的SwiftUI中的TextField上展开可单击区域 [英] Expande clickable area on TextField in SwiftUI, Xcode 11.2

查看:109
本文介绍了在Xcode 11.2中的SwiftUI中的TextField上展开可单击区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

can't figure out how to make clickable area larger to open keyboard on swiftUI (iOS 13, Xcode 11.2). I can only affect visual appearance but not the actual area the user can click on (clickable area == whatever the placeholder text's fontSize is.)

在swiftUI中创建TextField时,可以使用frame()来增大占位符文本周围的大小,并且我也可以使用fontsize来使框内的字体变大,但是没有什么可以使可点击区域(弹出键盘)变大而不会使字体变大.

When creating a TextField in swiftUI, it is possible to use frame() to increase size around placeholder text, and I can also use fontsize to make font inside box bigger, but nothing makes clickable area (that brings up keyboard) larger without making font much bigger.

//用于修改文本字段的代码

//Code used to modify 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

I would like it if when you click on anywhere inside the frame, the keyboard opened up/ you were able to type into the textField. However, I need to click on just the upper part of the placeholder Text in order to type into the TextField

推荐答案

好,所以我想出了一种解决方法,但不完全是解决方案.只需将TextField嵌入按钮中,无论您在何处单击,它都会立即打开

Ok so I figured a workaround but not exactly a solution; simply embed the TextField in a button and it opens right away no matter where you click

这篇关于在Xcode 11.2中的SwiftUI中的TextField上展开可单击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆