0

The behaviour i want is as follows; to use a textfield which is not editable and be able to scroll through long text by default tap and hold with magnifying glass , and after releasing, i want to dismiss focus on the same textfield.

First i put :

textfield.inputView = [[UIView alloc] initWithFrame:CGRectZero];

which forces the keyboard not to appear, but the focus is still on textfield. I tried using textview for horizontal scrolling by changing contentSize by didn't work. So i need any helpful info you can tell me, and if you needed further explanation i will clarify more.

user3488205
  • 357
  • 3
  • 7

2 Answers2

0

Problem with your approach - If you make UITextfield non editable it will also not take touches which will cause scrolling.

My suggestion => if you want scrolling+non editable field then you can do like.. Use UILabel for your text,for scrolling effect you can put this label inside UIScrollview for magnifying effect you can borrow code from HERE. and you can apply this magnification on nay view so you can use it on your UILabel.This will do all you ask for.

Hope it helps !

jnix
  • 480
  • 3
  • 10
  • Thanks for your reply, i tried your label+scrollview approach, but what i meant by not editable is that i can't modify it's content, and used textfield to maintain iOS behaviour in especially 2 points: 1. The indication of long text by the last 3 dots. 2. tap and hold to be able to scroll, don't care much about magnifying glass itself. – user3488205 Apr 02 '14 at 08:48
0

How about disabling the keyboard like here:

Disable UITextField keyboard?,

and then catch all input characters in the

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
                  replacementString:(NSString *)string

function, return NO for every entry. That should do what you want.

Community
  • 1
  • 1
TheEye
  • 9,280
  • 2
  • 42
  • 58
  • This way prevents me from entering characters, but i don't want the keyboard to appear, i just want the user to scroll throughout textfield with ought being able to edit, nor showing up the keyboard and after scrolling to lose focus on textfield. – user3488205 Apr 02 '14 at 09:03
  • Did you read the first part about disabling the keyboard on your text field? – TheEye Apr 02 '14 at 09:06
  • yes i did, tried it but didn't let me scroll throughout the text. – user3488205 Apr 02 '14 at 09:16
  • Just tried it (with UITextView) - works perfectly fine with me ... no keyboard, and scrolling is possible ... – TheEye Apr 02 '14 at 09:29
  • Maybe with (UITextView) but i need it for (UITextField) especially for horizontal scrolling – user3488205 Apr 02 '14 at 09:37
  • Also tried it with UITextField now, works like a charm (and it should, text view and text field are very much alike ...). Are you sure you did set the UITextField's delegate to your class so you indeed get the shouldChangeCharactersInRange call? – TheEye Apr 02 '14 at 09:44
  • I insured that i set up the delegate right, wrote both delegate methods but was not able to scroll the text at all. – user3488205 Apr 02 '14 at 10:47
  • Do you see the cursor blinking when you tap into the text field? – TheEye Apr 02 '14 at 10:48
  • You should see a blinking cursor when you tap it - the above measures do not disable the text field. Is your text field not editable? It has to be editable. – TheEye Apr 02 '14 at 11:23
  • Yes it is editable, but maybe because i am using Xcode 4.6.3, does it make a difference ? – user3488205 Apr 02 '14 at 14:49
  • Maybe - I'm on XCode 5.1. Any reason you didn't switch yet? It's a lot ore stable, and solved some pretty nasty issues. – TheEye Apr 02 '14 at 14:51
  • Well because it has a better support for iOS 6, which is very important to the project i'm working on. Anyway, i tried it without ShouldBeginEditing and it worked, but still one problem, which is that i want after the disappearing of magnifying glass, to end editing of the textfield, do you have any suggestions ? – user3488205 Apr 02 '14 at 15:01
  • Should still work, there's nothing special about the things I do. Maybe try with a clean UITextField in a test app, maybe you changed some attribute somewhere that causes the problem and forgot about it. – TheEye Apr 02 '14 at 15:03
  • Hmm, I don't think there is an event you can catch for that. – TheEye Apr 02 '14 at 15:04
  • Maybe another idea of ending editing of textfield ? after scrolling, after touch and hold or any other idea ? – user3488205 Apr 02 '14 at 15:05