UITextInput: selectedTextRange vs. markedTextRange? - ios

Ok, so I know Apple's UITextInput protocol requires the two UITextRange properties selectedTextRange and markedTextRange and the documentation says that selectedTextRange is a subrange of markedTextRange which is an uncomfirmed text range by the user yatta yatta. That still doesn't make some things clear to me regarding how I ought to implement the two text ranges differently. Could someone visually explain to me the difference between selectedTextRange and markedTextRange? I know that when the length of selectedTextRange is 0 it indicates a blinking caret at selectedTextRange's location. But what the heck is "marked text"?? I've only seen the following for text views in iOS:
Which I assume represents the current selectedTextRange. What does markedTextRange look like? Or is it basically the exact same thing? I'm so confused :( Thanks in advance for any help! The documentation has proven itself useless in my understanding of how to implement the UITextInput protocol.
EDIT
Does implementing markedTextRange have anything to do with the fact that some text in a view could be "markable" but "readonly" and selectedTextRange indicates the subrange in the "marked text", markedTextRange, that is readwrite?

From Apple documentation for UITextInput:
Marked text, which is part of multistage text input, represents provisionally
inserted text that the user has yet to confirm. It is styled in a distinctive
way. The range of marked text always contains within it a range of selected
text, which might be a range of characters or the caret.
Hence markedTextRange gets useful with languages that requires multistage input, e.g. Japanese.
In simple words: what user types is yet to be confirmed before it can be added to the value of the text input control is were markedTextRange gets into the game. GIF bellow demonstrates markedTextRange in action:
Notice slight sapphire background behind the unconfirmed hieroglyphs. Once text gets confirmed either by hitting enter/return, selecting option from suggestions or finger tap on text area after the marked text gets added to the input control value and background gets removed.
Notes:
markedTextRange has nothing to do with read-only text
I was not able to achieve multiple symbols selection within markedTextRange

Related

IBM BPM Coach - Disabling button immediately when an empty value is there in Decimal View Text Field

With Plain Text views I am able to do that by writing this code in on input event -
if (potential.trim() == "") {
${Button3}.setEnabled(false);
}
else{
${Button3}.setEnabled(true);
}
I don't know what potential means here in BPM but this works for Plain Text Views.
However when I try on change event in Decimal View Text field this doesn't work.
In html inspector console I see -
Potential reference not found.
Is there any Potential like thing available for Decimal Views also?
Judging by the documentation and looking at in on an 8.6 version it seems like 'potential' is an additional parameter available to the Plain Text control.
With that in mind, I don't think there is an equivalent for the Decimal view as it doesn't have an "On input" event available. You could, however, get something close to the same behavior using the "On Change" or "On blur" events of the Decimal view to check the binding value. If it's been set to null you could disable the button.
While that doesn't meet your exact requirement of immediate feedback, it does appear to work quickly enough that even if the user attempts to click the button without "committing" change to the Decimal input (meaning the cursor is still in the Decimal input field and they haven't pressed return) that the change and visibility settings happen first so the button won't execute.

Code input text field

Is there a native UI control for code input text field, for example like Whatsapp:
No. To achieve this, they're almost certainly tapping into the textField:shouldChangeCharactersInRange:replacementString: method for their UITextField, selectively accepting and formatting user input to match the dash-if-empty approach.
Further, I'm sure they've subclassed the field; per your comments there isn't a blue cursor - which isn't standard for a UITextField.
No there isn't. Use a UITextField, fill it with dashes, keep track of how many characters the user has entered, and replace the dashes accordingly as the user types.
There's a 4-digit code input text field called CodeInputView written in Swift.
In the past I've added a UITextField to the view and set its hidden == true. Then I show/hide the keyboard by calling becomeFirstResponder()/resignFirstResponder() on it. I listen for text did change notifications and update a visible label with the value of the hidden text field.

Add a Text Link to a TextView

Is it possible to add a text link into a TextView? I want the link to perhaps behave like a button, where I can assign an action to it.
EDIT: When I say assign an action, I mean actually giving it something in the code. I'm wondering if it's possible to dynamically add a "button" into text that I can assign a coded action to.
Live scenario
Think of something like a dictionary app. Maybe the definition of one word uses another word that you might not know the definition of, so being able to click on that word to instantly search it rather than having to type it in would be a nice user friendly feature. It seems rather unlikely, though, I guess.
I would recommend using NIAttributedLabel from Nimbus, an open source iOS library. You can specify text ranges that are links, and you get delegate messages sent when a user taps on it.
Main Nimbus site: http://nimbuskit.info/
NIAttributedLabel docs: http://docs.nimbuskit.info/interface_n_i_attributed_label.html
in the inspector, go to the Text View Attributes tab then make sure "Detect Links" is checked.
Yes you can. Add the URL into the text view, then open up the Attributes Inspector. You will see an option in there to detect links.
I know of a way, but its a LOT of work. First, you have an NSAttributedString that you have the text view display. Second, attribute the range of text you want to be the button. Third, assign a tap gesture recognizer to the text view and in the method called by the recognizer, you'll use core text to determine if the tap happened over the range of text that represents the buttons.
Heres how youll use core text: create a framesetter with the attributed string. Create a frame from the framsetter with the shape of a square that is the frame of the text view, inset by the padding of the text view. The frame will allow you to get the y origins of every line in the text view and and once you know what line the tap happened on, you can use the line to then figure out exactly what character was tapped on that line by giving it an x offset. Once you know character index on the line, you can add it to the beginning of the range of the line and get the index of the character within the whole string. Then you can check if its within the range of the text that is your button. If it is, you can then call a method to simulate a target action type behavior.
Ive explained the process of how to accomplish this and specified what kinds of core text objects youll need, ill let you look up the specific api details:
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CoreText_Framework_Ref/_index.html#//apple_ref/doc/uid/TP40005304
You can also use my objc core text wrapper:
https://github.com/mysterioustrousers/MYSCoreText
What about CoreText? It Can draw many kinds of Text .

Entering/Clearing specific UITextfields?

My aim is to have text boxes - a set amount per level for people to guess a hidden word. I don't want the UITextfield to be tapped and then bring up the keyboard, I'd like to have a different button that brings up the keyboard - if that's possible.
If each box is a separate text field how could I go about entering text. When a user types on the standard apple keypad, how could each character be inputted into a certain text field. I'd preferably like the text to show in the box as soon as a key is tapped.
I'm also having trouble clearing certain letters. Say a user mis-spells something and doesn't realise until the keyboard has resigned as first responder, how could I make it so that a user can tap on maybe two boxes if the rest of the word is spelt right and the program clear it?
Is there any way of writing the program so that it inputs text only if the text field is empty? Continuing with the example above they switch two letters, they tap to clear, they then bring up the keypad and the next key then pressed fills the empty boxes. Not allowing the program to input text in a used text field that only contains a single character?
I'm using Cocos2d - I don't know if that makes a difference. I hope you understand what I mean, although I'm rather bad at explaining.
Thank you in advance for your time and any help :).
Instead of having a textbox that you don't want users to edit, why not use a label?
To show the keyboard, you need to have it linked to some UITextField (or similar). You could use an invisible UITextField, and then monitor the input and send the characters to the correspinding labels. Refer to this question.
To check if a textfield has anything in it:
[textField.text length] > 0, but I would use labels instead of textfields.
I dont really understand the other parts of your question.

UITextView UIResponderStandardEditActions Text Formatting Toggle State

How do I determine the current state of the UIResponderStandardEditActions for text formatting? For example, if I do the following:
[textView toggleBoldface:nil];
How do I query the textView to find out if the state of bold is now on or off? This is for just a cursor with no selection (i.e. range length is 0). As such, enumerateAttribute doesn't seem to work.
Thank you.
It appears the typingAttributes property (available in iOS 6) will log the attributes that will be applied to new text typed by the user, even with a selection length of 0. Thus revealing what the state of formatting options such as bold will be.
NSLog(#"textViewFormatting options: %#", [[self noteTextView] typingAttributes]);
I'm not finding anything useful in the docs, but I suppose it would be simple enough to just subclass UITextView, add a property on it like BOOL boldText and then wherever you call [textView toggleBoldFace:nil]; just toggle that property as well. And then when you need to check the state of the textView, just check the boldText property instead.

Resources