Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First UITextview text is not showing

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.

enter image description hereenter image description here

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.

enter image description here

like image 558
Horray Avatar asked Dec 22 '14 08:12

Horray


2 Answers

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.

like image 87
Gregzo Avatar answered Oct 23 '22 02:10

Gregzo


Swift 5
This worked for me:

textView.isScrollEnabled = false
like image 37
faris97 Avatar answered Oct 23 '22 03:10

faris97