Accessibility (VoiceOver) on NSAttributedString - ios

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.

Related

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

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

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.

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 do you have two fonts in one UITextView (Xcode)?

I'm trying to make two font styes in one UITextView, how do I do this?
From the class reference:
This class does not support multiple styles for text. The font, color,
and text alignment attributes you specify always apply to the entire
contents of the text view. To display more complex styling in your
application, you need to use a UIWebView object and render your
content using HTML.
You cannot have two on the same page because it is not supported. Just use a webview and an HTML file
You can know use this by using the attributedText property of UITextView. This is available under iOS 6
UITextView supports just a single font, but there's a different topic on something similar:
Can I use multiple font style in UITextView?
If the text you want to draw is simple, I'd suggest subclassing UITextView or UIView, overwriting the drawRect function and work with some extra variables of your own. This only works if you have a very predictable system to the fonts though.
Another option is using multiple labels, which would probably need an ever more predictable setup.

Resources