I Inserted multiple UITextviews on a viewController, and the first textViews text is not showing until I double click on it. It then scrolls up, and if I double click on it again, it scrolls back down and I can't see it anymore.
I then tried to add UITextViews in the actual manually, (not programmatically,) and it did the same thing. The weird thing is that this only happens to one uitextview on the page.
Update
I'll post the code, but I don't think it's relevant because as I said I manually put the UITextViews on another vieController, and it did the same thing, but I'll post it just in case:
int heightBetweenLabels = 10;
int labelWidth = 200;
int labelHeight = 1;
int height = 0;
int position = 0;
for (int i = 0; i < [currentListInfo count]; i++) {
if (height == 0 && position == 0)
{
height = 70;
labelHeight = 50;
}
label = [[UITextView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - labelWidth) / 2, height + position + heightBetweenLabels, labelWidth, labelHeight)];
[label setBackgroundColor:[UIColor lightGrayColor]];
[label setTextColor:[UIColor blackColor]];
label.scrollEnabled = NO;
[label setEditable:NO];
self.label.text = nil;
label.dataDetectorTypes = UIDataDetectorTypeAll;
[self textViewFitToContent:label];
[self.view addSubview:label];
[label setText:[currentListInfo objectAtIndex:i]];
label.contentInset = UIEdgeInsetsZero;
height = label.frame.size.height;
position = label.frame.origin.y;
}
Update - 2
This is basically what is happening. I don't know why, but the textView text - "name", is lowered than all the others.
UIViewController has a automaticallyAdjustsScrollViewInsets property which is YES by default. As UITextView is a ScrollView, the first UITextView you add will have a top inset automatically added to it.
Solution: in your view controller's viewDidLoad or init, set self.automaticallyAdjustsScrollViewInsets to NO.
Swift 5
This worked for me:
textView.isScrollEnabled = 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