I know the TextView
is embedded in a ScrollView
. And if there is a fairly long String
(Which contains no "\n"
)
The TextView
will automatically do the line-wrap, according to the width of the TextView
.
If TextView
's height is short, then we are able to scroll it vertically.
How do you disable the auto line-wrap? Such that, if there are no "\n" encounters, it does not line wrap. Rather, it lets the user scroll horizontally to view the text.
How can I implement this?
[myTextView setContentSize:CGSizeMake(width, myTextView.frame.size.height)];
The width of the content extends past the width of the textView's frame or else it won't scroll.
UIScrollView
. Reference:- DualScrollTextViewI figure out how to do this with many helps of you guys :D, thanks, and here we go!
1. So, firstly, We need a longlonglong String, right?
2. Assume we have a UIScrollView which is linked by
@IBOutlet
or got by calling the.viewWithTag(xxx)
.We will let it be named asscroll
:3. It's time to get the size of our string, here is a key function we'll use it:
Oh! I almost forget to define what kind of Font( this's a crucial parameter ) we will use, and What is the max-size of our string's size
4. OK, now we can put the string into a textView, you need to programmatically create a new
UITextView
, so that we can define the frame which is identical to the string's size(Oh, maybe a little bigger :D) :5. Back to our
scroll
, we will set itscontentSize
:scroll.contentSize = CGSizeMake(size.width, size.height)
6. Finally, addSubview:
scroll.addSubview(textView)
[I hope this will help]
I think this should plug and play, but I know for sure that
textView.sizeThatFits
works. You have to make sure that you constrain your text view to it's parent scrollview for it to work. (Leading, Trailing, Top, Bottom and the Height.)