Expande clickable area on TextField in SwiftUI, Xcode 11.2

拜拜、爱过 提交于 2019-12-22 06:35:40

问题


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

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

//Where i call the modifier

TextField("email address", text: $email).modifier(SignInModifier()).disableAutocorrection(true).keyboardType(.emailAddress)

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


回答1:


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



来源:https://stackoverflow.com/questions/58618470/expande-clickable-area-on-textfield-in-swiftui-xcode-11-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!