I've got a UITextView I'm using that has clickable links in it (ie, html links). I've set scrolling to be disabled.
By default "User Interaction Enabled" is false, and scrolling does not occur. However, in order to get the links to be clickable, "User Interaction Enabled" must be true. Given that, even with scrolling disabled, it is still possible to scroll the text if it exceeds the height of the UITextView.
My text is supposed to fit in the UITextView, so mostly this isn't a problem, however sometimes there is extra space at the bottom, and it cuts off a couple lines, and I don't want to ever allow that scrolling.
Is there a way to forcefully disable scrolling given these circumstances?
How about just disabling vertical scrolling via the UITextView delegate like this:
- (void)scrollViewDidScroll:(id)scrollView
{
CGPoint origin = [scrollView contentOffset];
[scrollView setContentOffset:CGPointMake(origin.x, 0.0)];
}
UPD:
1) As I understand you use textview just for displaying text with links, there are no editing or scrolling. If you add it using Interface Builder - make sure that you turned of editing, scrolling, selection options like on the screenshot. But selection might be on for URL detection.
Or do it in code using properties editable, selectable, scrollEnabled
2) If you want unselectable textview with URL - you might look for other control to archive this. Look at OHAttributedLabel, it is multi-lined and has link detection, and no text selection or scrolling.
Related
The iOS13 Voice Control feature has a command 'Scroll Down'. This command works for UITableViews but does not seem to work for UIScrollViews with scrollable content.
Is this intended?
Intended or not, is there a way to enable this command to work on a UIScrollView?
Example: a UILabel with a lot of text inside a UIScrollView (constraints are correct - it scrolls and is acknowledged by Voice Over saying 'Page 1 of 3' when active)
This command works for UITableViews but does not seem to work for UIScrollViews with scrollable content.
... only if this content is a huge UILabel content that must be scrollable: add many other elements (sliders, buttons...) and you'll notice that scrolling is enabled.
About that, in the TextKit Best Practices (2018 WWDC video), it's highly recommended to use a UITextView for this purpose:
Is there a way to enable this command to work on a UIScrollView?
Switch the label and your scroll view for a text view instead to make the Voice Control feature work with your specific use case.
Otherwise, it works with many other elements different from UILabel: the scroll view knows its content size and when it has to scroll down/up but the Voice Control feature doesn't recognize the label content as an element to directly interact with inside a scroll view.
I tested with a button and a huge UILabel as you did:
Scroll down that worked to reach the end of my label.
Scroll up that never works.
The label seems to be a kind of empty box that Voice Control ignores in a scroll view: to enable this command in a scroll view, just replace your label by a text view.
Now, if your use case is a single UILabel in a UIScrollView, remove them to display a UITextView instead.
EDIT
Here's the Xcode screenshot to make the UITextView scrolling work with the VoiceControl feature:
... with the results hereunder:
As you can notice, this is just a blank project with a simple text view: iOS recognizes this single element and acts as desired when Scroll down and Scroll up are vocalized.
I've got a set of UIImageViews contained inside of a UIScrollView. For some reason, when I go to have Voice Over read all the elements on the page, it does not read the ImageView like it should. I set up the UIImageView's accessibility info like so:
if (self.featuresModel.imageText) {
self.featureImage.isAccessibilityElement = YES;
self.featureImage.accessibilityLabel = self.featuresModel.imageText;
}
I've checked that the UIScrollView is not set to be accessible, so it's not intercepting the touches. It seems to show it will work in the simulator, when I click on the image it pops up the correct label and highlights the correct area, however, on a physical device, clicking or trying to read all elements on the page does nothing when it gets to the UIImageView.
Any ideas on how to remedy this issue?
Edit: The scrollView class is a custom subclass of UIScrollView that doesn't implement UIAccessiblity protocol directly, however, since it uses a UIScrollView as its underlying data structure, I don't think this should matter much, however, as I still don't know much about UIAccessibility I thought I should mention it.
Make sure you enabled the accessibility for your imageview on storyboard/nib.
IF you set the isAccessibilityElement to YES, the voice over highlights it and reads it. Again the accessibility for that element should be enalbled in nib.
IF you set the isAccessibilityElement to NO, the voice over doesnt highlights it and doesnt reads it, even the accessibility for that element is enalbled in nib.
Note: Voice over doesnt care about scrolview.It only care about the elements in the scroll view. You can change the order of the accessibility elements if you want.Or you can disable the accessibility for the elements in the scroll view.
I have a TextView made in the Interface Builder;
It scrolls fine with its default text, but as soon as I programatically set the text to something else, it no longer scrolls.
I do not disable scrolling, and I have tried enabling scrolling (setScrollEnabled:YES), and user interaction (setUserInteractionEnabled:YES) both of which make no difference.
The things that I have found:
It scrolls with the default text showing
It doesn't seem to matter what text I set in it, it just stops scrolling as soon as it is set. I'm doing it programatically like this:
self.myTextView.text = #"any text"; (or [self.myTextView setText:#"any text"]; has the same effect.)
I have two other Textfield in the same View, one of which is using the View Controller as its delegate. The TextField in question is not using the View Controller as its delegate. None of the delegate methods set anything to do with scrolling.
Both of the other TextViews have their scrolling capability set to defaults. If I change the one that doesn't need it to no scrolling, it makes no difference to the problem.
The one that has the View Controller as its delegate continues to scroll after I edit it (non programatically) and this one continues to be able to scroll once the one in question freezes.
If I delete these two other TextFields, then the one in question works as expected, i.e. it scrolls after adding text.
Any thoughts?
Thanks.
Make sure your new text is long enough to be able to get scroll.
if text is just one line it wont scroll but if its larger then text area size then it will scroll its by default settings
I am displaying logs in the scroll-able text view, I want to retain this functionality but disable the keyboard. I have tried the unchecking in Behaviour of the Attribute Inspector, but it disables the scroll view too.
Can anyone guide me what options I have?
Just set the editable property of UITextView to NO or FALSE. GOod Luck!
I have a UITextView with autocorrection on. The view's height is about 30 pix. When autocorrect kicks in the autocorrect view is nearly invisible below the text. Is there a way to control the position of the small autocorrect window or insure it is the top layer so it is always visible and the user can easily see and interact with it?
I discovered that setting the scrollEnabled to false on the UITextView the popup would always appear above the word being corrected.
Did you try to set clipsToBounds=NO for your UITextView? Sounds like it's clipping the autocorrect view to the frame size of your UITextView..or perhaps auto-positioning it inside your frame. Worth a try anyway..
After trying various solutions unsuccessfully, I find the best way that worked for me is to simply add your UITextView inside a UIView.