Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView text not starting from top

I have a UITextView. I want its text to start from top but I it is not coming from top. Please have a look at my code :

UITextView *myTextView = [[UITextView alloc] init]; myTextView.frame = rect; myTextView.editable = NO; myTextView.font = [UIFont fontWithName:@"Helvetica" size:MAIN_FONT_SIZE]; myTextView.backgroundColor = [UIColor clearColor]; myTextView.text = sourceNode.label; myTextView.dataDetectorTypes = UIDataDetectorTypeAll; [cell.contentView addSubview:myTextView]; [myTextView sizeToFit]; [self alignTextToTopTextView:myTextView];  

alignTextToTopTextView:

-(void)alignTextToTopTextView :(UITextView*)textView{      CGRect frame = textView.frame;     frame.size.height = textView.contentSize.height;     textView.frame = frame; }  

Please see the below screenshot.

UITextView is on the right side.

enter image description here

like image 471
Nitish Avatar asked May 29 '12 03:05

Nitish


2 Answers

Set the Content Inset like this in your UITextView

youtextView.contentInset = UIEdgeInsetsMake(-7.0,0.0,0,0.0); 

Adjust the Top value the way you want. this shoud fix your problem.

EDIT:

If you're having issues with iOS7 or above, try using...

[yourTextView setContentOffset: CGPointMake(x,y) animated:BOOL];

like image 179
Damitha Raveendra Avatar answered Oct 02 '22 19:10

Damitha Raveendra


in the viewDidLoad method add

self.automaticallyAdjustsScrollViewInsets = false 
like image 31
masouk Avatar answered Oct 02 '22 20:10

masouk