I have 2 text fields for input on an iOS app, one for name and one for email. I want to use TouchScreenKeyboardType.NamePhonePad and TouchScreenKeyboardType.EmailAddress for the corresponding fields. I have seen the docs at [TouchScreenKeyboard.Open][1]
public string nameText;
public string emailText;
// make name text field
nameText = GUI.TextField(new Rect(200, 300, 400, 55), nameText, 60, nameGS);
// make email field
emailText = GUI.TextField(new Rect(200, 375, 400, 55), emailText, 80, nameGS);
I’m sure many people have done this but I can’t seem to put it together. Thanks for any help
In case anyone else is dealing with this, I ended up writing my own plugin to create native iOS textfields and textViews. It was a little tricky but not too bad. Writing a plugin basically involves creating a class in xcode, making some class methods that do what you need and then creating C methods that call the Obj-C class methods, then calling the C method in a Unity class using the method Unity shows in their docs. Building iOS Plugins
I started out by extending a plugin that I purchased and then just took what I learned from that and made my own. Here’s a snippet:
+ (void)createNameTextField:(CGFloat*)xValue yValue:(CGFloat*)yValue width:(CGFloat*)width height:(CGFloat*)height placeholder:(NSString*)placeholder returnKey:(NSString*)returnKey autoCorr:(NSString*)autoCorr font:(NSString*)font fontSize:(CGFloat*)fontSize
{
CGRect frame = CGRectMake(*xValue, *yValue, *width, *height);
nameField = [[UITextField alloc] initWithFrame:frame];
nameField.keyboardType = UIKeyboardTypeNamePhonePad;
nameField.placeholder = placeholder;
[nameField setFont:[UIFont fontWithName:font size:*fontSize]];
nameField.delegate = self;
nameField.tag = 1;
// setting return key type
if ([returnKey isEqualToString:@"default"]) {
nameField.returnKeyType = UIReturnKeyDefault;
}
else if ([returnKey isEqualToString:@"next"]) {
nameField.returnKeyType = UIReturnKeyNext;
}
else if ([returnKey isEqualToString:@"done"]) {
nameField.returnKeyType = UIReturnKeyDone;
}
else {
NSLog(@"Error: choose a valid return key option (default, next, or done)");
}
// setting auto correct type
if ([autoCorr isEqualToString:@"yes"]) {
nameField.autocorrectionType = UITextAutocorrectionTypeYes;
}
else if ([autoCorr isEqualToString:@"no"]){
nameField.autocorrectionType = UITextAutocorrectionTypeNo;
}
else if ([autoCorr isEqualToString:@"default"]){
nameField.autocorrectionType = UITextAutocorrectionTypeDefault;
}
else {
NSLog(@"Error: choose a valid autocorrection option (yes, no, or default)");
}
NSLog(@"returnKey: %@", returnKey);
NSLog(@"autoCorr: %@", autoCorr);
[UnityGetGLViewController().view addSubview:nameField];
}