UITextField customization for how text is selected or inserted - ios

I'm planning to work on a small customization of UITextField to change a certain UI/UX design features.
I know UITextField has a certain inbuilt methods to change the border style, color, etc. But if I wish to make a lot of customization, can someone guide me how I should begin?
Do I need to refer to the UITextField parent class to modify it? Or I will have to make a custom UI object right from the scratch?
EDIT:
The customization I plan on working is how we select/de-select or choose an insertion point for the text in the UITextField.

It sounds like you're going to want to take advantage of the fact that UITextField adopts the UITextInput protocol. You can do that by subclassing UITextField. Alternatively, it might be sufficient for your needs to set up some other class as a delegate of this UITextField - that depends on whether the UITextFieldDelegate notifies you with a sufficiently fine grain that the user is up to something in the text field.

Related

Is it possible to add a Done key to ALL keyboards in an app?

Is it possible to add a done or cancel key which dismisses a keyboard to all keyboards in an iOS app? There are several posts asking how to dismiss a keyboard via a cancel or done button, but the solutions are on a field by field basis.
Are there any solutions that add this functionality globally so the code wont need to be duplicated for each textfield/area in an application?
Like #silentBob says in his answer, the inputAccessoryView of a text field is the view that’s displayed immediately above the keyboard when the text field is the first responder. If you didn’t want to write an extension on UITextField to override the -inputAccessoryView method, you could also create a subclass of UITextField to do the same, which would make it easier to determine which method is going to be called. You could also have multiple subclasses of UITextField to customize which button(s) appear. If you have a text field in a storyboard, you can simply change the class to your custom subclass, so while you have to go through and make those changes, you don’t have to do it in code.
Yes, you can add an extension to UITextField class, which should add a UIToolbar with Done and Cancel actions as UITextField inputAccessoryView.
Well, In that case you have to customise the keyboard, built your own keyboard and do whatever you need to do with your key in the keyboard.

Can I implement "select" and "copy" on UILabel when it has a long press just as UITextField (UITextView、UIWebView), and how?

Please give me a hand~ I wanna know how to make UILabel have a system Clipboard(e.g. copy and select) like UITextField (UITextView、UIWebView) when it has a long press, which makes me can copy the text I want. I have read some demo on Github, however, they always only contain copy function, which makes me can't choose the text I want to copy. At present I wanna implement "select" on UILabel but I don't know how to work out.
Can I use UITextField without editing function? But once I turn off editing function, there is no system Clipboard when it has a long press.
Or if there is a simpler method to work out? Thanks!
You're gonna have to implement it yourself. There isn't anything too special about any of the system text views, just read the docs for UIPasteboard, specifically around -[UIPasteboard setString:]. The rest just comes down to how you want to implement the UI. For that I'd recommend looking into subclassing UILabel just to keep everything tidy; UIMenuController for showing the callout view; implementing -canBecomeFirstResponder, -canPerformAction:forSender:, and -copy: to customize the callout actions; and UILongPressGestureRecognizer for triggering everything.

UIAccessibilityFocus protocol not working with UITextField

With UIAccessibilityFocus protocol, supposedly, if you override accessibilityElementDidBecomeFocused() and accessibilityElementDidLoseFocus(), you will be able to track when an accessible element gain or lose focus while Voiceover is running. This seems to work well with all field types - UIButton, UILabel, UISwitch, UITextView, etc. - except UITextField. When Voiceover focus is on (or leaving) an UITextField, those functions are simply not called. Just wondering if it is a bug or something else. Thanks!
This is a feature, let me explain.
Without VoiceOver turned on there is no concept of focus within iOS. Except in the case of UITextField. UITextFields get "focused" (again focus isn't really a concept in iOS without voiceover) with or without VoiceOver on. For the other elements, this is not the case. They do not have "gainFocus" equivalents. A UIButton gaining focus is only meaningful from an accessibility standpoint. So they add in the special accessibilityElementDidGainFocus calls for those classes. They are specifically removed from UITextFields because that call would be logically equivalent to calls that already exist for that class, independent of the Accessibility API.

Is there a way to override UITextView UIKeyInput so can enter text from superview?

I have a view TextViewHolder that has a UITextView as a subview. I'd like for TextViewHolder to implement UIKeyInput and it's three accompanying methods insertText, hasText, and deleteBackwards so that I can insert the text in my UITextView from TextViewHolder (for messy design purposes) and I'd also like to maintain the functionality of an editable UITextView (ala positioning of the cursor, copy paste, ability to add different languages). Is it possible to accomplish this without subclassing the UITextView?
Not possible to do unfortunately, need to subclass UITextView and override insertText and deleteBackward.

custom input view keyboard functionality

I wanted to ask a quick question just to make sure I am not missing anything simple before I implement a more difficult method. I need to create a custom keyboard for an iPhone application. This I have already done by creating a view with the buttons, using a custom input view and it displays exactly like it should. Now most of the buttons are standard numbers which need to update a UITextField in the screen that called the keyboard. Does anyone know a simple way to do this? I assume there has to be a built in function that the keyboard uses to send the information but I haven't been able to find any reference to it. Otherwise I will have to go the more difficult route. If anyone has a simple way to do this I would appreciate it. I haven't worked with custom keyboards before.
You won't be able to do it the same way that Apple does it, as their keyboard is basically an input device, globally.
I recommend you just append the data in your button press multiplex method. Here's an example:
NSString *appendThisText = #"subtitle";
self.myTextView.text=[NSString stringWithFormat:#"%#%#", self.myTextView.text, appendThisText];
Custom keyboards are simpler than you realise.
UITextField conforms to the UITextInput protocol. That's a bit of a red-herring because this protocol provides all the really complex stuff like selecting text and so on. But UITextInput itself conforms to UIKeyInput. This is your friend.
The key UIKeyInput methods are:
- (void)insertText:(NSString *)text;
- (void)deleteBackward;
Your keyboard class should have a delegate (which points to the textfield that the keyboard is operating on) and you simply call these methods to insert and delete text.

Resources