Can I place noneditable text in UITextField - ios

I'd like to place some fixed text inside an UITextField, but before the insert point, sort of like this:
| He went (towaards)
...where "towaards" is the editable part.
The point is to show the editable text in context.
Is that possible, and/or are there better alternatives?

I guess you can do that by implementing UITextFieldDelegate. There is one method – textField:shouldChangeCharactersInRange:replacementString:.
In this method you can check each and every character which is entering by user (even backspace). So first you implement change in another NSString object then validate with your condition.
Check whether new string passes through your validation then replace the old string with new string, otherwise leave it as it is.
For example, check new string starts with your string or not. You can use this:
[myString hasPrefix:#"He went"];
Here in the same method you can also do one more thing, when user taps on UITextField check if #"(towaards)" string is there in textField then remove that text by code.
Hope this is what you want.

Just set the text property of the label to #"He went (towaards) and when editing is started change it to #"He went "

I don't think you can put noneditable and editable text in the same UITextField.
What about putting a UILabel with the noneditable text right beside the UITextField ?

Related

How to animate the entry and deletion of characters on UITextField?

I would like to animate the user entry and deletion character by character in UITextField. For example, I want each character bounce in and bounce out when user is entering or deleting them.
Is there a formal way to do that by overriding some methods in UITextField ? Or I need to do a trick by using another UILabel or somehow, do you have an idea ?
Thanks in advance.

UITextField with partial edit

I want to use a UITextField so that only part of it will be editable.
I know about the delegation and shouldChangeCharactersInRange but for some reason, copying the ranged part is allowed.
My goal is to get similar result to this (the 'subject' text part) without being able to copy it.
Should i use a different UITextField with textFieldDidBeginEditing returning false all the time?
Is there a better solution?
In the screenshot, a UILabel placed next to the UITextField is used. I'd recommend doing this as it will give you more options when you decide to style the text.

iOS Text field delegate if the value of a text field is programatically

I have tried many an attempts to make this work. After much googling, trial & error, I post this here.
I have a text field whose value is changed when a slider near by is moved.
So in the IBAction sliderChanged, I have this
self.amountTextField.text = self.amountSlider.value
Now, I would like to be notified of this change in the text field value. I have tried with quite a few delegates. It so happens that when the text field's value is changed by tapping on the text field and changing it using the keyboard, these delegates are fired. But when the value is changed using the above piece of code, the delegates are not invoked.
I do like to know if theres a possible solution for this, i.e, i would like a delegate to handle the change in the text field value even if its done from code. Would love to have a working example. Thanks in advance.

How can I create a UITextField with ability display both text and emoticon?

I need create a UITextField, which can display both text and emoticon. Example, when I type : "abc :)", I will get "abc" text and smile-emoticon. So, how can I do that ?
My idea is create a UIView custom, every text is a UILabel, every emoticon is a UIImageView. But I see it is very complex. I want to find a simpler solution.
Thank for your support.
try pbrmojilable library
It may help you.

copy text from textfield with not enabling keyboard

i have a uitextfield and some text on it, i want to know how to create a code that my user touch the field and can copy the txt to use for something else.
my uitextfiled.enable = no;
thanks
As far as the copying goes, you need to check out the UIPasteboard Class. Using that class, you can put text onto the pasteboard very easily.
For not enabling the text field, you can simply leave it disabled, but capture the touch event anyway.
For the pasteboard, try going through this tutorial.
I you are able to use UITextField class instead you could set the editable property to NO. Selecting text will still be possible.

Resources