Need shouldInteractWithURL delegate to be called in a non-selectable UITextView - ios

I am using UITextView to show some text including some clickable names.
UITextViews are in chat bubbles so I don't want them to be selectable but I found that the delegate method shouldInteractWithURL is called if only the UITextView is selectable.
Is there any way that I can make some parts of text clickable with URL behind, while my UITextView is not selectable?

Apple documentation of isSelectable say:
This property controls the ability of the user to select content and
interact with URLs and text attachments. The default value is true.
So it looks like to handle URLs you have to enable Selectable.
If you decide to do that you can do it in code free way

Related

UITextView responding unexpected to accessibility voice over

Currently I am walking through my whole iOS app to optimize it for accessibility voice over. When it comes to the UITextView, which I subclassed, voice over is not acting like I thought it would. My UITextView subclass is only changing a path's color on the superview's layer in becomeFirstResponder and resignFirstResponder. So nothing special on my UITextView subclass that could interfere with accessibility.
As long as there is no text in the UITextView it is acting as expected. Voiceover tells me that it is a text field and that I can double tap it to edit. But as soon as there is text in the UITextView, the only thing voice over tells me, is the value of the UITextView. Voice over doesn't tell me anymore that this is an editable text field.
Am I doing something wrong? Why is it acting like that?
I do appreciate any help!
If you didn't edit any accessibility hints or labels for the text field it should act accordingly. If selected it should say:
It is a text field
If you are editing it
The editing mode you are in
The value of the text field (nil if empty)
Where the cursor is
Then while you type it says the letters you are entering as you enter them. When you hit space or enter it should say the word you just typed. As long as your text field is exhibiting these behaviors you should be fine.
Tip: if you want to know how accessibility elements should act, try using a native iOS app with accessibility turned on and compare it with your app.

Accessibility (VoiceOver) on NSAttributedString

I have a block of text in a UITextView built using NSAttributedString. I require VoiceOver to say something extra when certain portions of the text is touched.
Is it possible to add accessibility attributes to NSAttributedString?
I think one solution to this would be a custom subclass of UITextView. Then you can return an array of UIAccessibilityCustomAction in an override of accessibilityCustomActions. These objects not only describe the actions taken by the text view, but they also allow VoiceOver to execute them.

UITextView scrolls up after "Speak"

I have a non-editable UITextView to display some text. Users can select the text in this UITextView and choose the iOS "Speak Selection" functionality (speak button) to read it for them. However, when 'Speak' is done reading the last word, it scrolls up the UITextView. In fact, even if I select just the last word in the text, and choose 'Speak', it scrolls up the UITextView.
I have scrollEnabled set to NO, editable set to NO, and the text is a NSAttributedString.
How can I stop the UITextView to scroll up in this case?
I can't comment with my reputation, unfortunately I don't have a real answer but a workaround; so far mine is to intercept [UITextView setContentOffset:animated] via method swizzling (http://nshipster.com/method-swizzling/) and avoid calling the original method when needed (this method is called by QuickSpeak function). I guess subclassing would be cleaner if you can instantiate the view yourself (this is not my case).

detect urls in UILabel

I have a Tableview and tableview cell is customized to have a UILabel. The text in UILabel is having URLs. Is there a way to detect urls like how UITextView will enable detect URLs so that user interaction should be able to load the urls.
If you just want to identify the URLs, you can use NSDataDetector with the NSTextCheckingTypeLink checking type.
If you want to draw the URLs differently, and you are targeting iOS 6, you can use an NSAttributedString to turn the URLs blue or underline them or whatever. If you're targeting an older version of iOS, you will probably want to look for some free code on the Internet to draw styled text, like OHAttributedLabel.
If you want to actually make the URLs touch-sensitive, you can add a tap gesture recognizer to the label and try to figure out which part of the string was tapped (somewhat complicated), or look for some free code on the Internet that already does it for you (like OHAttributedLabel), or just put a UITextView in the table view cell instead of a label.
as Rob point out how can we achieved the same is awesome.
But, we can use a tact so can save with issue of ios version (possibly), just by using a UILabel and UIButton.
What we need to do is that, either from IB or story-board,just place a UILabel with string as URL(use this as title), say;
"www.myURL.com"
Now, just above it, place a UIButton(button with custom type), and just use "______"(underline) and set this button as overlap your UILabel and also the 'underline' must be beneath your label.
Now, just do in action of button whatever you required as you need on the click of URL and here also you can change the textColor, etc, properties; also load URL and navigate to UIWebView.

How can I put icons inside a UITextField?

I want to create a custom input view, some of whose buttons insert "icons" into the selected UITextField, like the "RSS" or "Reader" icons which sometimes appear on the right hand side of the URL input field in Mobile Safari. I want the icons to be intermingled with the text and for all intents and purposes (like selection, cut and paste and deletion) behave like normal character glyphs.
Is there a name for these icons? Is there an API for creating them or do I have to build this entirely from scratch?
The leftView and rightView properties (instances of UIView) of the UITextField class are exactly for this purpose, and you can control their behaviour using the leftViewMode and rightViewMode properties. I suggest you to read the UITextField class reference for further details.
According to this question, what I want is an NSTokenField and there's not one available in stock iOS. However, there are some implementations on GitHub.

Resources