2

I have one UITextView whose height is 568 (means fit in screen size) and if i write 50 lines in it then it will definitely scroll vertically.

But i want to scroll (or just bounce) when there is only one line of text.

When user scroll Vertically then the text will just bounce in UITextView.

in my application the UITextView is not Editable.

Any idea, code,link will be great help...

EDIT:

The UITextView's height will be that 568 only.
it will not change (means without changing the height of UITextView, set this thing).

[txtView setContentOffset:CGPointMake(0, 1000)];

It is not working too...

Sam
  • 431
  • 7
  • 23
  • If your UITextView content size is below of your UITextView frame, it should not be scrollable. – Natarajan Mar 22 '14 at 06:53
  • You may refer this link http://stackoverflow.com/questions/19046969/uitextview-content-size-different-in-ios7 – Natarajan Mar 22 '14 at 06:58
  • nop... it's not working...i want just bounce the text in textview. with less text in it. – Sam Mar 22 '14 at 07:02

2 Answers2

0

Set the frame of UITextView

CGRect frame = textView.frame;
frame.size = textView.contentSize;
textView.frame = frame;

See: UITextView change height instead of scroll

Community
  • 1
  • 1
DharaParekh
  • 1,730
  • 1
  • 10
  • 17
  • and it's not working because it's just set the frame but textview's frame is static. so with less content it should scroll or just bounce vertically. do you have any other idea ? if you don't have any code then okay..no need any code just an idea...i'll implement by my self. but stuck here... – Sam Mar 22 '14 at 07:04
0

If you want to scroll TextView text that not Larger then it height . then you can't do this. you wont getting scroll bar if your textView's Text not larger then its frame height.

Setting [txtView setContentOffset:CGPointMake(0, 1000)]; wont work anymore if that data in not longer then textView's height.

UPDATE:-

Here it is i got one trick. If textview not editable and you just want to scroll it try to add your Textview in to one scrollviw. Like Bellow i got this working.

in .h class

@property(nonatomic,retain)IBOutlet UITextView *textvie;
@property(nonatomic,retain)IBOutlet UIScrollView *sceoll;

in .m class

- (void)viewDidLoad
{
    [sceoll setContentSize:CGSizeMake(0, 500)];
    [textvie setTextAlignment:NSTextAlignmentCenter];
    textvie.editable = FALSE;
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        textvie.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    } else {
        textvie.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
    }
 [super viewDidLoad];

}

in xib enter image description here

and the result is:-

enter image description here

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Hi Nitin...we are linked in Linkedin...so good to see you here...and i need any idea that the text will just bounce in text view...i thought to put spaces at the end of the text that is less then height. but if there is any better solution then it's good... – Sam Mar 22 '14 at 07:21