0

I would like to display the keyboard when I tap on the image and use the keyboard for displaying letters I've touched and stock them in a variable NSString. (like Snapchat). How can I display the letters in "live" ?

I've made UIGestureRecognizer and recognizer for the location where I've tapped. Here is my code:

-(void)tapDetected:(UIGestureRecognizer*)recognizer{
NSLog(@"tap detected.");
CGPoint point = [recognizer locationInView:self.truckImageView];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, point.y, 300, 40)];
[textField becomeFirstResponder];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[self.view addSubview:textField];
NSLog(@"x = %f y = %f", point.x, point.y );
Vjardel
  • 1,065
  • 1
  • 13
  • 28

1 Answers1

0

There's no way to show up UIKeyboard with UIImage officially.

When user touches the image, add UITextField at the point and set the firstResponder. You don't even need to use drawText:.

Ryan
  • 4,799
  • 1
  • 29
  • 56
  • Ok, but can I use this UITextField for displaying a text on image like snapchat do ? I just need to make UITextField in a CGRect for making that? thanks for replying! :) – Vjardel Jul 22 '14 at 06:51
  • @Viny76 Yes, you can. NSAttributedText is also available for UITextField. – Ryan Jul 22 '14 at 06:53
  • I've edited my tapDetected method. Now it's alright : When I tap on the image, UITextField appears, but if I want to send this image to friends, the image doesn't have UITextField, how can I fix it ? thanks !!! :) – Vjardel Jul 22 '14 at 14:07
  • @Viny76 that is a big enough question that you should probably post it as a new question. In short, you have to snapshot the view hierarchy to create a new image that includes your text on top of the image. – Zev Eisenberg Jul 22 '14 at 14:24
  • @ZevEisenberg thank you man, I've found how to create a snapshot, now my method works fine !!! :) – Vjardel Jul 22 '14 at 14:35