How to disable select functionality in UITextView? - iphone

I want to create a text display area (either UILabel or UITextView) in my iPhone app which (1) allows scrolling and (2) does not allow selection. I have tried the following techniques unsuccessfully:
Basic UILabel: Didn't allow
scrolling, and clipped text to the
bottom of UILabel space on screen.
Giant UILabel within a UIScrollView: the UILabel kept placing the text (vertically) at the center of the giant UILabel, so it often was outside of my UIScrollView.
UITextView: So far this approach has worked the best, because it scrolls and does not clip the text. I can even subclass UITextView to enable resizing the text to fit within the textview, and passing any touch events to the superview to detect taps & swipes. But, when the user taps and holds on the text itself, the text selection interface appears. I am not interested in this interface and it actually is distracting from the user's experience. I have tried to subclass canPerformAction:withSender:, but apparently this function is called after the tap event--not before it.
Does anyone know how to disable the text selection interface in UITextView, without also disabling scrolling?

Take option number 2, but set the numberOfLines property on your UILabel to 0. This will set the number of lines to 'unlimited' and prevent the vertical centring of the text.
Don't forget to set the lineBreakMode property to UILineBreakModeWordWrap so that your text doesn't run off the side of the UILabel.

Related

UITextView interferes scrolling of UIScrollView

The problem I am encountering now is that there is a UITextView component in UIScrollView and that UITextView component will interfere the scrolling of UIScrollView, i.e. when a user's finger is on that UITextView to scroll the whole UIScrollView, the screen won't scroll. The content in the UITextView is dynamic, i.e. the size of UITextView component is dynamic. The worst case is the whole screen is occupied by the UITextView and users won't be able to scroll the screen at all.
The UITextView is disabled for editing. I choose UITextView instead of UILabel because I want to detect phone number & link in the supplied text and utilize the built-in function to invoke dialer and browser when users click the phone number or link.
Any suggestion about how I can solve this problem or any clue about why this happens are all appreciated! Thanks.
UITextView inherits from UIScroll view so it has a property scrollEnabled. Just put it to false!
If you are using a storyboard or nib file, select your UITextView and uncheck Scrolling Enabled in Interface Builder.
Otherwise, do this:
textView.scrollEnabled = NO;
Apart from the property scrollEnabled, you also have the property userInterationEnabled that disable(if you set it to FALSE/NO) any touch events on the view (scrolling included, of course). Hope it helps, specially for other situations cos in your case it makes the same effect as disabling the scroll.

Keyboard accessory view hiding text

I have the following problem: I have a standard UITextView which I resize once the keyboard pops up. I also have another view which I animate into view (not the standard accessory view attached to the keyboard). The problem is that I do not want text to be hidden by this view. This is what happens when I reach the last line (orange view = my custom accessory view):
Ideally, I'd like to have an automatic scroll should that happen. But I have no clue how to achieve this if I am in the last line of the UITextView. Also, scrollToVisible doesn't work in this context and I don't know if I'd get anywhere with contentInset.
Any suggestions would be welcome! Thanks.
EDIT
I suppose I would need some kind of mechanism which would allow to
make the textview only expand to the line right above the accessory view if I was entering something on the LAST LINE
have the textview expand to the keyboard if I was not editing the LINE DIRECTLY ABOVE the KEYBOARD.
Does that make sense? What I need is the opposite of contentInset, I suppose.
I simply don't want to resize the textView to just above the accessory view as it takes away screen space to display text.
I got the solution- sorry, I guess it was obvious, but it took me the whole day to figure it out:
textOfPage.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
This will offset my UITextView so that the last line is never hidden. The 100 is in pixels and can be adjusted accordingly.
What I would do is resize the textview in the textViewShouldBeginEditing method to fit above the keyboard and the newly added accessory view, and then resize it back to full screen when the keyboard is dismissed in textViewShouldEndEditing

UIScrollView, UILabel, Tickers

I've created a monochrome ticker [think stock ticker] to display information the user encounters within my app. It's a wide and narrow instance of UIScrollView whose content is filled by an instance of UILabel with the relevant text. The parent view is its own delegate and takes care of the horizontal scrolling animation. The UILabel instance is set to one line only.
I'd like for the text to be in two colors (red and black) where necessary, and possibly plain and italics again where necessary. Of course UILabel is not capable of doing this, and neither is UITextView.
The obvious thing to try is replacing the UILabel instance with an instance of UIWebView and send it an html-string to format the text. However the results are not yet quite as satisfying as with UILabel - the text has margin offsets, for instance, and it needs to be displayed on one line.
Another solution, which works but I'm not satisfied with, is to have the UIScrollView display a concatenated sequence of UILabel instances each with the appropriate font or text color.
With regard to the UIWebView solution what do you advise? For instance, how would you configure an instance of a UIWebView to visually and faithfully resemble the UILabel?
check out the fancy label example at http://furbo.org/2008/10/07/fancy-uilabels/
if it helps you.

UItextView in UITableview, autocorrection bubble not visible

I have a UITableView with custom cells. The cells containing one UITextView each and the cell is resizing during user type text in the TextView. My problem is when user is on first row in a TextView autocorrection bubbles wont be visible in the current cell. Is there any workaround or can someone point me to another direction?
alt text http://img340.imageshack.us/img340/5414/skrmavbild20100519kl092.png
If the cell is resizing as the user types, you could set the minimum height of the edited cell to have enough height for the bubbles. Always measure the active cell as if there were at least two lines.
Each UIView has a clipsToBounds property that controls wether contents can be drawn outside the bounds. You might be able to set this to NO for all views in the hierarchy between the bubble and cell. This could have other side effects though.
Also, make sure the active cell has a higher Z order than neighboring cells. It could simply be that the next cell down is drawing over the bubble, as opposed to the active cell cropping the bubble.
I propose you a "workaround"
Your user try to edit a row in your table view
-> You present a modal view with a UITextView with dismiss and ok button.

Resize UILabel text with swipe to delete

I am having some trouble getting my application to properly resize the text of UILabels when the user does a swipe to delete or other type of delete. Currently, the delete button is covering up the text that is in the cell (if it is really long). I would like for them to operate like how SMS (move clipped text down a line) or iPod (delete button resizing text).
I am using a custom UITableViewCell I am working with two labels, UIImageView and a couple of subviews for backgroundView and selectedBackgroundView. I have been playing with the springs and struts of the labels in the cell and partially attained my desired effect however, the text has a weird, quick resizing bug where it becomes deformed and stretched out and then is returned proper size when the delete button is done animating.
As far as other things that I have tried, I have made sure that my text does not adjust-to-fit and I have made my minimum font size the font size that I set for the label. I have also tried over-riding layoutSubviews but that didn't seem to have any effect at all.
If a screenshot (of the deforming label) or code would be helpful, I can post both but since nothing I have done is working, I figured they would be of little value.
fixed it by setting the "mode" of the label in the view panel to "left"
It sounds like you need to set the number of lines property and the wrap property for the labels.
If your actively changing the size of the label itself, you might want to animate that change.