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.
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];
in the viewDidLoad method add
self.automaticallyAdjustsScrollViewInsets = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With